Pretty results display

This commit is contained in:
RunasSudo 2017-11-24 19:51:10 +11:00
parent 529166867f
commit 247f050d5b
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 26 additions and 8 deletions

View File

@ -55,12 +55,26 @@ class ApprovalQuestion(Question):
choices = ListField(StringField()) choices = ListField(StringField())
min_choices = IntField() min_choices = IntField()
max_choices = IntField() max_choices = IntField()
def pretty_answer(self, answer):
return ', '.join([self.choices[choice] for choice in answer.choices])
class ApprovalAnswer(Answer): class ApprovalAnswer(Answer):
choices = ListField(IntField()) choices = ListField(IntField())
class RawResult(Result): class RawResult(Result):
answers = EmbeddedObjectListField() answers = EmbeddedObjectListField()
def count(self):
combined = []
for answer in self.answers:
index = next((i for i, val in enumerate(combined) if val[0] == answer), None)
if index is None:
combined.append([answer, 1])
else:
combined[index][1] += 1
combined.sort(key=lambda x: x[1], reverse=True)
return combined
class Election(TopLevelObject): class Election(TopLevelObject):
_id = UUIDField() _id = UUIDField()

View File

@ -154,6 +154,11 @@ class EosObject(metaclass=EosObjectType):
return self._instance[0].recurse_parents(cls) return self._instance[0].recurse_parents(cls)
return None return None
def __eq__(self, other):
if not isinstance(other, EosObject):
return False
return EosObject.serialise_and_wrap(self) == EosObject.serialise_and_wrap(other)
@staticmethod @staticmethod
def serialise_and_wrap(value, object_type=None, for_hash=False, should_protect=False): def serialise_and_wrap(value, object_type=None, for_hash=False, should_protect=False):
if object_type: if object_type:

View File

@ -16,12 +16,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
#} #}
<ul class="ui list"> <table class="ui celled table">
{% for answer in election.results[loop.index0].answers %} {% for answer, num in election.results[loop.index0].count() %}
<li> <tr>
{% for choice in answer.choices %} <td>{{ question.pretty_answer(answer) }}</td>
{{ question.choices[choice] }}, <td>{{ num }}</td>
{% endfor %} </tr>
</li>
{% endfor %} {% endfor %}
</ul> </table>