diff --git a/auth/auth_systems/__init__.py b/auth/auth_systems/__init__.py index 676d268b31af5dab2fccf2264874c8b663679edd..39f5ef14314d57671f71fec507dd80f6508f7d42 100644 --- a/auth/auth_systems/__init__.py +++ b/auth/auth_systems/__init__.py @@ -4,7 +4,7 @@ AUTH_SYSTEMS = {} import twitter, password, cas, facebook, google, yahoo, linkedin AUTH_SYSTEMS['twitter'] = twitter AUTH_SYSTEMS['linkedin'] = linkedin -#AUTH_SYSTEMS['password'] = password +AUTH_SYSTEMS['password'] = password AUTH_SYSTEMS['cas'] = cas AUTH_SYSTEMS['facebook'] = facebook AUTH_SYSTEMS['google'] = google diff --git a/helios/datatypes/legacy.py b/helios/datatypes/legacy.py index 36cbe9de26d79a109a0017b727753bc18734c4a5..a9fe99422e857be9d3125f04eb816766f799086b 100644 --- a/helios/datatypes/legacy.py +++ b/helios/datatypes/legacy.py @@ -5,6 +5,7 @@ Legacy datatypes for Helios (v3.0) from helios.datatypes import LDObject, arrayOf, DictObject, ListObject from helios.crypto import elgamal as crypto_elgamal from helios.workflows import homomorphic +from helios import models ## ## @@ -14,7 +15,7 @@ class LegacyObject(LDObject): USE_JSON_LD = False class Election(LegacyObject): - WRAPPED_OBJ_CLASS = homomorphic.Election + WRAPPED_OBJ_CLASS = models.Election FIELDS = ['uuid', 'questions', 'name', 'short_name', 'description', 'voters_hash', 'openreg', 'frozen_at', 'public_key', 'cast_url', 'use_voter_aliases', 'voting_starts_at', 'voting_ends_at'] diff --git a/helios/models.py b/helios/models.py index 415132824b7d25cda174dcd509feb3f2db7999e7..7765b00bab51f94408290288ceceb17d01824cae 100644 --- a/helios/models.py +++ b/helios/models.py @@ -258,8 +258,7 @@ class Election(HeliosModel): if t.public_key == None: issues.append("trustee %s hasn't generated a key yet" % t.name) - return issues - + return issues def ready_for_tallying(self): return datetime.datetime.utcnow() >= self.tallying_starts_at @@ -455,6 +454,63 @@ class Election(HeliosModel): else: return "Closed" + @classmethod + def one_question_winner(cls, question, result, num_cast_votes): + """ + determining the winner for one question + """ + # sort the answers , keep track of the index + counts = sorted(enumerate(result), key=lambda(x): x[1]) + counts.reverse() + + # if there's a max > 1, we assume that the top MAX win + if question['max'] > 1: + return [c[0] for c in counts[:question['max']]] + + # if max = 1, then depends on absolute or relative + if question['result_type'] == 'absolute': + if counts[0][1] >= (num_cast_votes/2 + 1): + return [counts[0][0]] + else: + return [] + + if question['result_type'] == 'relative': + return [counts[0][0]] + + @property + def winners(self): + """ + Depending on the type of each question, determine the winners + returns an array of winners for each question, aka an array of arrays. + assumes that if there is a max to the question, that's how many winners there are. + """ + return [self.one_question_winner(self.questions[i], self.result[i], self.num_cast_votes) for i in range(len(self.questions))] + + @property + def pretty_result(self): + if not self.result: + return None + + # get the winners + winners = self.winners + + raw_result = self.result + prettified_result = [] + + # loop through questions + for i in range(len(self.questions)): + q = self.questions[i] + pretty_question = [] + + # go through answers + for j in range(len(q['answers'])): + a = q['answers'][j] + count = raw_result[i][j] + pretty_question.append({'answer': a, 'count': count, 'winner': (j in winners[i])}) + + prettified_result.append({'question': q['short_name'], 'answers': pretty_question}) + + return prettified_result class ElectionLog(models.Model): """ diff --git a/helios/workflows/homomorphic.py b/helios/workflows/homomorphic.py index 7eaea4b614edd37d1cb61cd8256c13089fb8b6b2..a5c4291c2bbccd0662195cc479a31f8ea601139d 100644 --- a/helios/workflows/homomorphic.py +++ b/helios/workflows/homomorphic.py @@ -220,70 +220,6 @@ class EncryptedVote(WorkflowObject): return return_val -class Election(models.Election): - - class Meta: - abstract = True - - @classmethod - def one_question_winner(cls, question, result, num_cast_votes): - """ - determining the winner for one question - """ - # sort the answers , keep track of the index - counts = sorted(enumerate(result), key=lambda(x): x[1]) - counts.reverse() - - # if there's a max > 1, we assume that the top MAX win - if question['max'] > 1: - return [c[0] for c in counts[:question['max']]] - - # if max = 1, then depends on absolute or relative - if question['result_type'] == 'absolute': - if counts[0][1] >= (num_cast_votes/2 + 1): - return [counts[0][0]] - else: - return [] - - if question['result_type'] == 'relative': - return [counts[0][0]] - - @property - def winners(self): - """ - Depending on the type of each question, determine the winners - returns an array of winners for each question, aka an array of arrays. - assumes that if there is a max to the question, that's how many winners there are. - """ - return [self.one_question_winner(self.questions[i], self.result[i], self.num_cast_votes) for i in range(len(self.questions))] - - @property - def pretty_result(self): - if not self.result: - return None - - # get the winners - winners = self.winners - - raw_result = self.result - prettified_result = [] - - # loop through questions - for i in range(len(self.questions)): - q = self.questions[i] - pretty_question = [] - - # go through answers - for j in range(len(q['answers'])): - a = q['answers'][j] - count = raw_result[i][j] - pretty_question.append({'answer': a, 'count': count, 'winner': (j in winners[i])}) - - prettified_result.append({'question': q['short_name'], 'answers': pretty_question}) - - return prettified_result - - class DLogTable(object): """