diff --git a/helios/datatypes/__init__.py b/helios/datatypes/__init__.py index d3b5271ef918e7baefc4758b1617babd41964742..cee651e4e14c103426a15385ad9f00221e12c6ac 100644 --- a/helios/datatypes/__init__.py +++ b/helios/datatypes/__init__.py @@ -177,7 +177,10 @@ class LDObject(object): self._setattr_wrapped(f, new_val) def serialize(self): - return utils.to_json(self.toDict()) + d = self.toDict() + if self.USE_JSON_LD: + d['#'] = {'_': 'http://heliosvoting.org/ns#'} + return utils.to_json(d) def toDict(self, alternate_fields=None): val = {} diff --git a/helios/view_utils.py b/helios/view_utils.py index 1219e9b7825034d96cff8cff5d9d6e74a0f94824..084a696f6636f6a09df476cb11f2f72535955194 100644 --- a/helios/view_utils.py +++ b/helios/view_utils.py @@ -10,6 +10,8 @@ from django.shortcuts import render_to_response import utils +from helios import datatypes + # nicely update the wrapper function from functools import update_wrapper @@ -81,7 +83,11 @@ def json(func): web client. """ def convert_to_json(self, *args, **kwargs): - return render_json(utils.to_json(func(self, *args, **kwargs))) + return_val = func(self, *args, **kwargs) + if isinstance(return_val, datatypes.LDObject): + return render_json(return_val.serialize()) + else: + return render_json(utils.to_json(return_val)) return update_wrapper(convert_to_json,func) diff --git a/helios/views.py b/helios/views.py index c71bf3c425feff89db00003ad0b21588b95974d9..3a4f1d606916b23130aa49e24623d5afbabbe756 100644 --- a/helios/views.py +++ b/helios/views.py @@ -214,7 +214,7 @@ def one_election_schedule(request, election): def one_election(request, election): if not election: raise Http404 - return election.toJSONDict() + return datatypes.LDObject.instantiate(election, datatype='legacy/Election') @election_view() def election_badge(request, election):