Pretty results display
This commit is contained in:
parent
529166867f
commit
247f050d5b
@ -56,12 +56,26 @@ class ApprovalQuestion(Question):
|
||||
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()
|
||||
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 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:
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user