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())
min_choices = IntField()
max_choices = IntField()
def pretty_answer(self, answer):
return ', '.join([self.choices[choice] for choice in answer.choices])
class ApprovalAnswer(Answer):
choices = ListField(IntField())
class RawResult(Result):
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):
_id = UUIDField()

View File

@ -154,6 +154,11 @@ class EosObject(metaclass=EosObjectType):
return self._instance[0].recurse_parents(cls)
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
def serialise_and_wrap(value, object_type=None, for_hash=False, should_protect=False):
if object_type:

View File

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