Skip to content
Snippets Groups Projects
Commit e9bbd3db authored by Ben Adida's avatar Ben Adida
Browse files

fixed views to use automatically generated linked data object, and added...

fixed views to use automatically generated linked data object, and added interface from full cast vote to short cast vote
parent e2dc41f2
No related branches found
No related tags found
No related merge requests found
...@@ -274,8 +274,8 @@ class BaseArrayOfObjects(LDObject): ...@@ -274,8 +274,8 @@ class BaseArrayOfObjects(LDObject):
def __init__(self, wrapped_obj): def __init__(self, wrapped_obj):
super(BaseArrayOfObjects, self).__init__(wrapped_obj) super(BaseArrayOfObjects, self).__init__(wrapped_obj)
def toDict(self): def toDict(self, complete=False):
return [item.toDict() for item in self.items] return [item.toDict(complete=complete) for item in self.items]
def loadData(self): def loadData(self):
"go through each item and LD instantiate it, as if it were a structured field" "go through each item and LD instantiate it, as if it were a structured field"
......
...@@ -11,7 +11,7 @@ class BigInteger(LDObject): ...@@ -11,7 +11,7 @@ class BigInteger(LDObject):
""" """
WRAPPED_OBJ_CLASS = int WRAPPED_OBJ_CLASS = int
def toDict(self): def toDict(self, complete=False):
if self.wrapped_obj: if self.wrapped_obj:
return str(self.wrapped_obj) return str(self.wrapped_obj)
else: else:
...@@ -22,7 +22,7 @@ class BigInteger(LDObject): ...@@ -22,7 +22,7 @@ class BigInteger(LDObject):
self.wrapped_obj = int(d) self.wrapped_obj = int(d)
class Timestamp(LDObject): class Timestamp(LDObject):
def toDict(self): def toDict(self, complete=False):
if self.wrapped_obj: if self.wrapped_obj:
return str(self.wrapped_obj) return str(self.wrapped_obj)
else: else:
......
...@@ -66,14 +66,14 @@ class Voter(LegacyObject): ...@@ -66,14 +66,14 @@ class Voter(LegacyObject):
ALIASED_VOTER_FIELDS = ['election_uuid', 'uuid', 'alias'] ALIASED_VOTER_FIELDS = ['election_uuid', 'uuid', 'alias']
def toDict(self): def toDict(self, complete=False):
""" """
depending on whether the voter is aliased, use different fields depending on whether the voter is aliased, use different fields
""" """
if self.wrapped_obj.alias != None: if self.wrapped_obj.alias != None:
return super(Voter, self).toDict(self.ALIASED_VOTER_FIELDS) return super(Voter, self).toDict(self.ALIASED_VOTER_FIELDS, complete = complete)
else: else:
return super(Voter,self).toDict() return super(Voter,self).toDict(complete = complete)
class ShortCastVote(LegacyObject): class ShortCastVote(LegacyObject):
...@@ -86,6 +86,10 @@ class CastVote(LegacyObject): ...@@ -86,6 +86,10 @@ class CastVote(LegacyObject):
'cast_at' : 'core/Timestamp', 'cast_at' : 'core/Timestamp',
'vote' : 'legacy/EncryptedVote'} 'vote' : 'legacy/EncryptedVote'}
@property
def short(self):
return self.instantiate(self.wrapped_obj, datatype='legacy/ShortCastVote')
class Trustee(LegacyObject): class Trustee(LegacyObject):
FIELDS = ['uuid', 'public_key', 'public_key_hash', 'pok', 'decryption_factors', 'decryption_proofs', 'email'] FIELDS = ['uuid', 'public_key', 'public_key_hash', 'pok', 'decryption_factors', 'decryption_proofs', 'email']
...@@ -143,9 +147,9 @@ class EGZKDisjunctiveProof(LegacyObject): ...@@ -143,9 +147,9 @@ class EGZKDisjunctiveProof(LegacyObject):
"hijack and make sure we add the proofs name back on" "hijack and make sure we add the proofs name back on"
return super(EGZKDisjunctiveProof, self).loadDataFromDict({'proofs': d}) return super(EGZKDisjunctiveProof, self).loadDataFromDict({'proofs': d})
def toDict(self): def toDict(self, complete = False):
"hijack toDict and make it return the proofs array only, since that's the spec for legacy" "hijack toDict and make it return the proofs array only, since that's the spec for legacy"
return super(EGZKDisjunctiveProof, self).toDict()['proofs'] return super(EGZKDisjunctiveProof, self).toDict(complete=complete)['proofs']
class DLogProof(LegacyObject): class DLogProof(LegacyObject):
WRAPPED_OBJ_CLASS = crypto_elgamal.DLogProof WRAPPED_OBJ_CLASS = crypto_elgamal.DLogProof
...@@ -170,7 +174,7 @@ class Questions(LegacyObject): ...@@ -170,7 +174,7 @@ class Questions(LegacyObject):
def loadDataFromDict(self, d): def loadDataFromDict(self, d):
self.wrapped_obj = d self.wrapped_obj = d
def toDict(self): def toDict(self, complete=False):
return self.wrapped_obj return self.wrapped_obj
......
...@@ -84,10 +84,10 @@ def json(func): ...@@ -84,10 +84,10 @@ def json(func):
""" """
def convert_to_json(self, *args, **kwargs): def convert_to_json(self, *args, **kwargs):
return_val = func(self, *args, **kwargs) return_val = func(self, *args, **kwargs)
if isinstance(return_val, datatypes.LDObject): try:
return render_json(return_val.serialize())
else:
return render_json(utils.to_json(return_val)) return render_json(utils.to_json(return_val))
except:
import pdb; pdb.set_trace()
return update_wrapper(convert_to_json,func) return update_wrapper(convert_to_json,func)
...@@ -319,7 +319,7 @@ def socialbuttons(request): ...@@ -319,7 +319,7 @@ def socialbuttons(request):
@election_view() @election_view()
def list_trustees(request, election): def list_trustees(request, election):
trustees = Trustee.get_by_election(election) trustees = Trustee.get_by_election(election)
return [datatypes.LDObject.instantiate(t, 'legacy/Trustee').toDict() for t in trustees] return [t.toJSONDict(complete=True) for t in trustees]
@election_view() @election_view()
def list_trustees_view(request, election): def list_trustees_view(request, election):
...@@ -1172,7 +1172,9 @@ def ballot_list(request, election): ...@@ -1172,7 +1172,9 @@ def ballot_list(request, election):
after = datetime.datetime.strptime(request.GET['after'], '%Y-%m-%d %H:%M:%S') after = datetime.datetime.strptime(request.GET['after'], '%Y-%m-%d %H:%M:%S')
voters = Voter.get_by_election(election, cast=True, order_by='cast_at', limit=limit, after=after) voters = Voter.get_by_election(election, cast=True, order_by='cast_at', limit=limit, after=after)
return [datatypes.LDObject.instantiate(v.last_cast_vote(), 'legacy/ShortCastVote').toDict() for v in voters]
# we explicitly cast this to a short cast vote
return [v.last_cast_vote().ld_object.short.toDict(complete=True) for v in voters]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment