From e2dc41f2caedd407f617e38eacc97ed598376275 Mon Sep 17 00:00:00 2001 From: Ben Adida <ben@adida.net> Date: Mon, 17 Jan 2011 18:42:53 -0800 Subject: [PATCH] fixed level where json ld is applied --- helios/datatypes/__init__.py | 14 ++++++++------ helios/models.py | 5 ----- helios/views.py | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/helios/datatypes/__init__.py b/helios/datatypes/__init__.py index cee651e..2a641e6 100644 --- a/helios/datatypes/__init__.py +++ b/helios/datatypes/__init__.py @@ -80,8 +80,8 @@ class LDObjectContainer(object): return self._ld_object - def toJSONDict(self): - return self.ld_object.toJSONDict() + def toJSONDict(self, complete=False): + return self.ld_object.toJSONDict(complete=complete) def toJSON(self): return self.ld_object.serialize() @@ -177,12 +177,10 @@ class LDObject(object): self._setattr_wrapped(f, new_val) def serialize(self): - d = self.toDict() - if self.USE_JSON_LD: - d['#'] = {'_': 'http://heliosvoting.org/ns#'} + d = self.toDict(complete = True) return utils.to_json(d) - def toDict(self, alternate_fields=None): + def toDict(self, alternate_fields=None, complete=False): val = {} for f in (alternate_fields or self.FIELDS): # is it a structured subfield? @@ -190,6 +188,10 @@ class LDObject(object): val[f] = recursiveToDict(self.structured_fields[f]) else: val[f] = self.process_value_out(f, self._getattr_wrapped(f)) + + if complete and self.USE_JSON_LD: + val['#'] = {'_': 'http://heliosvoting.org/ns#'} + return val toJSONDict = toDict diff --git a/helios/models.py b/helios/models.py index 54aa59e..084d585 100644 --- a/helios/models.py +++ b/helios/models.py @@ -26,11 +26,6 @@ from helios.datatypes.djangofield import LDObjectField import csv, copy -# global counters -GLOBAL_COUNTER_VOTERS = 'global_counter_voters' -GLOBAL_COUNTER_CAST_VOTES = 'global_counter_cast_votes' -GLOBAL_COUNTER_ELECTIONS = 'global_counter_elections' - class HeliosModel(models.Model, datatypes.LDObjectContainer): class Meta: abstract = True diff --git a/helios/views.py b/helios/views.py index 3a4f1d6..fe51542 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 datatypes.LDObject.instantiate(election, datatype='legacy/Election') + return election.toJSONDict(complete=True) @election_view() def election_badge(request, election): -- GitLab