Pretty results display
This commit is contained in:
parent
529166867f
commit
247f050d5b
@ -56,12 +56,26 @@ class ApprovalQuestion(Question):
|
|||||||
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()
|
||||||
workflow = EmbeddedObjectField(Workflow) # Once saved, we don't care what kind of workflow it is
|
workflow = EmbeddedObjectField(Workflow) # Once saved, we don't care what kind of workflow it is
|
||||||
|
@ -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:
|
||||||
|
@ -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>
|
||||||
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</li>
|
</table>
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user