From a3652e40de6ca6b318839c60eda69e8669efe876 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Thu, 23 Nov 2017 18:18:01 +1100 Subject: [PATCH] Basic election details display --- eos/base/election.py | 4 ++ eosweb/core/main.py | 40 +++++++++++++++--- eosweb/core/modelview.py | 30 +++++++++++++ eosweb/core/templates/base.html | 2 +- eosweb/core/templates/election/ballots.html | 42 +++++++++++++++++++ eosweb/core/templates/election/base.html | 6 ++- eosweb/core/templates/election/booth.html | 27 ++++++++++++ eosweb/core/templates/election/core/tabs.html | 23 ++++++++++ eosweb/core/templates/election/psr/tabs.html | 24 +++++++++++ eosweb/core/templates/election/questions.html | 26 ++++++++++++ eosweb/core/templates/election/trustees.html | 28 +++++++++++++ eosweb/core/templates/election/view.html | 6 ++- .../templates/question/approval/view.html | 23 ++++++++++ 13 files changed, 273 insertions(+), 8 deletions(-) create mode 100644 eosweb/core/modelview.py create mode 100644 eosweb/core/templates/election/ballots.html create mode 100644 eosweb/core/templates/election/booth.html create mode 100644 eosweb/core/templates/election/core/tabs.html create mode 100644 eosweb/core/templates/election/psr/tabs.html create mode 100644 eosweb/core/templates/election/questions.html create mode 100644 eosweb/core/templates/election/trustees.html create mode 100644 eosweb/core/templates/question/approval/view.html diff --git a/eos/base/election.py b/eos/base/election.py index 882f97e..f038678 100644 --- a/eos/base/election.py +++ b/eos/base/election.py @@ -35,8 +35,12 @@ class Ballot(EmbeddedObject): class Voter(EmbeddedObject): _id = UUIDField() + name = StringField() ballots = EmbeddedObjectListField() +class EmailVoter(Voter): + email = StringField() + class Question(EmbeddedObject): prompt = StringField() diff --git a/eosweb/core/main.py b/eosweb/core/main.py index 5c489df..d5ad746 100644 --- a/eosweb/core/main.py +++ b/eosweb/core/main.py @@ -24,6 +24,7 @@ from eos.psr.mixnet import * from eos.psr.workflow import * import eos.core.hashing +import eosweb import functools @@ -49,11 +50,12 @@ def setup_test_election(): # Set election details election.name = 'Test Election' - for i in range(3): - voter = Voter() - election.voters.append(voter) + voter = Voter() + election.voters.append(Voter(name='Alice')) + election.voters.append(Voter(name='Bob')) + election.voters.append(Voter(name='Charlie')) - election.mixing_trustees.append(MixingTrustee()) + election.mixing_trustees.append(MixingTrustee(name='Eos Voting')) election.sk = EGPrivateKey.generate() election.public_key = election.sk.public_key @@ -76,7 +78,7 @@ def setup_test_election(): @app.context_processor def inject_globals(): - return {'eos': eos, 'SHA256': eos.core.hashing.SHA256} + return {'eos': eos, 'eosweb': eosweb, 'SHA256': eos.core.hashing.SHA256} @app.route('/') def index(): @@ -93,3 +95,31 @@ def using_election(func): @using_election def election_view(election): return flask.render_template('election/view.html', election=election) + +@app.route('/election//booth') +@using_election +def election_booth(election): + return flask.render_template('election/booth.html', election=election) + +@app.route('/election//view/questions') +@using_election +def election_view_questions(election): + return flask.render_template('election/questions.html', election=election) + +@app.route('/election//view/ballots') +@using_election +def election_view_ballots(election): + return flask.render_template('election/ballots.html', election=election) + +@app.route('/election//view/trustees') +@using_election +def election_view_trustees(election): + return flask.render_template('election/trustees.html', election=election) + +# === Model-Views === + +model_view_map = {} + +# TODO: Make more modular +from . import modelview +model_view_map.update(modelview.model_view_map) diff --git a/eosweb/core/modelview.py b/eosweb/core/modelview.py new file mode 100644 index 0000000..8dcd623 --- /dev/null +++ b/eosweb/core/modelview.py @@ -0,0 +1,30 @@ +# Eos - Verifiable elections +# Copyright © 2017 RunasSudo (Yingtong Li) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from eos.base.election import * +from eos.psr.election import * + +model_view_map = { + ApprovalQuestion: { + 'view': 'question/approval/view.html' + }, + Election: { + 'tabs': 'election/core/tabs.html' + }, + PSRElection: { + 'tabs': 'election/psr/tabs.html' + } +} diff --git a/eosweb/core/templates/base.html b/eosweb/core/templates/base.html index 37774f5..6675a63 100644 --- a/eosweb/core/templates/base.html +++ b/eosweb/core/templates/base.html @@ -25,7 +25,7 @@ {% block basecontent %} diff --git a/eosweb/core/templates/election/ballots.html b/eosweb/core/templates/election/ballots.html new file mode 100644 index 0000000..64ce0e6 --- /dev/null +++ b/eosweb/core/templates/election/ballots.html @@ -0,0 +1,42 @@ +{% extends 'election/base.html' %} + +{# + Eos - Verifiable elections + Copyright © 2017 RunasSudo (Yingtong Li) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +#} + +{% block electioncontent %} + + + + + + + + + {% for voter in election.voters %} + + + {% if voter.ballot|length > 0 %} + + {% else %} + + {% endif %} + + {% endfor %} + +
VoterBallot fingerprint
{{ voter.name }}{{ SHA256().update_obj(voter.ballot[-1]).hash_as_b64() }}
+{% endblock %} diff --git a/eosweb/core/templates/election/base.html b/eosweb/core/templates/election/base.html index f0d0922..5b36f50 100644 --- a/eosweb/core/templates/election/base.html +++ b/eosweb/core/templates/election/base.html @@ -20,13 +20,17 @@ {% block title %}{{ election.name }}{% endblock %} +{% macro tab(name, view) %} + {{ name }} +{% endmacro %} + {% block content %}

{{ election.name }}

Election fingerprint: {{ SHA256().update_obj(election).hash_as_b64() }}

{% block electioncontent %} diff --git a/eosweb/core/templates/election/booth.html b/eosweb/core/templates/election/booth.html new file mode 100644 index 0000000..c7fc487 --- /dev/null +++ b/eosweb/core/templates/election/booth.html @@ -0,0 +1,27 @@ +{% extends 'base.html' %} + +{# + Eos - Verifiable elections + Copyright © 2017 RunasSudo (Yingtong Li) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +#} + +{% block title %}{{ election.name }} – Voting booth{% endblock %} + +{% block content %} +

{{ election.name }}

+ +

Election fingerprint: {{ SHA256().update_obj(election).hash_as_b64() }}

+{% endblock %} diff --git a/eosweb/core/templates/election/core/tabs.html b/eosweb/core/templates/election/core/tabs.html new file mode 100644 index 0000000..9add19b --- /dev/null +++ b/eosweb/core/templates/election/core/tabs.html @@ -0,0 +1,23 @@ +{# + Eos - Verifiable elections + Copyright © 2017 RunasSudo (Yingtong Li) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +#} + +{% block tabs %} + {{ tab('Overview', 'election_view') }} + {{ tab('Questions', 'election_view_questions') }} + {{ tab('Voters and ballots', 'election_view_ballots') }} +{% endblock %} diff --git a/eosweb/core/templates/election/psr/tabs.html b/eosweb/core/templates/election/psr/tabs.html new file mode 100644 index 0000000..d95f77d --- /dev/null +++ b/eosweb/core/templates/election/psr/tabs.html @@ -0,0 +1,24 @@ +{% extends 'election/core/tabs.html' %} + +{# + Eos - Verifiable elections + Copyright © 2017 RunasSudo (Yingtong Li) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +#} + +{% block tabs %} + {{ super() }} + {{ tab('Trustees', 'election_view_trustees') }} +{% endblock %} diff --git a/eosweb/core/templates/election/questions.html b/eosweb/core/templates/election/questions.html new file mode 100644 index 0000000..82b06c0 --- /dev/null +++ b/eosweb/core/templates/election/questions.html @@ -0,0 +1,26 @@ +{% extends 'election/base.html' %} + +{# + Eos - Verifiable elections + Copyright © 2017 RunasSudo (Yingtong Li) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +#} + +{% block electioncontent %} + {% for question in election.questions %} +

{{ loop.index }}. {{ question.prompt }}

+ {% include eosweb.core.main.model_view_map[question.__class__]['view'] %} + {% endfor %} +{% endblock %} diff --git a/eosweb/core/templates/election/trustees.html b/eosweb/core/templates/election/trustees.html new file mode 100644 index 0000000..626832d --- /dev/null +++ b/eosweb/core/templates/election/trustees.html @@ -0,0 +1,28 @@ +{% extends 'election/base.html' %} + +{# + Eos - Verifiable elections + Copyright © 2017 RunasSudo (Yingtong Li) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +#} + +{% block electioncontent %} +

Mixing trustees

+
    + {% for trustee in election.mixing_trustees %} +
  1. {{ trustee.name or 'Unnamed trustee' }}
  2. + {% endfor %} +
+{% endblock %} diff --git a/eosweb/core/templates/election/view.html b/eosweb/core/templates/election/view.html index 74b8668..6ba0122 100644 --- a/eosweb/core/templates/election/view.html +++ b/eosweb/core/templates/election/view.html @@ -23,7 +23,11 @@ {% block electioncontent %} {% if election.workflow.get_task('eos.base.workflow.TaskConfigureElection').status == Status.EXITED %} {% if election.workflow.get_task('eos.base.workflow.TaskOpenVoting').status == Status.EXITED %} -

Click here to vote in this election

+ {% if election.workflow.get_task('eos.base.workflow.TaskCloseVoting').status == Status.EXITED %} +

+ {% else %} +

Click here to vote in this election

+ {% endif %} {% else %}

{% endif %} diff --git a/eosweb/core/templates/question/approval/view.html b/eosweb/core/templates/question/approval/view.html new file mode 100644 index 0000000..540d278 --- /dev/null +++ b/eosweb/core/templates/question/approval/view.html @@ -0,0 +1,23 @@ +{# + Eos - Verifiable elections + Copyright © 2017 RunasSudo (Yingtong Li) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +#} + +
    + {% for choice in question.choices %} +
  • {{ choice }}
  • + {% endfor %} +