Basic election details display

This commit is contained in:
RunasSudo 2017-11-23 18:18:01 +11:00
parent 3fc98c8a36
commit a3652e40de
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
13 changed files with 273 additions and 8 deletions

View File

@ -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()

View File

@ -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/<election_id>/booth')
@using_election
def election_booth(election):
return flask.render_template('election/booth.html', election=election)
@app.route('/election/<election_id>/view/questions')
@using_election
def election_view_questions(election):
return flask.render_template('election/questions.html', election=election)
@app.route('/election/<election_id>/view/ballots')
@using_election
def election_view_ballots(election):
return flask.render_template('election/ballots.html', election=election)
@app.route('/election/<election_id>/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)

30
eosweb/core/modelview.py Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
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'
}
}

View File

@ -25,7 +25,7 @@
{% block basecontent %}
<div class="ui fixed inverted menu" style="margin-right: 1.5em;">
<div class="ui container">
<a href="#" class="header item">Eos Voting</a>
<a href="/" class="header item">Eos Voting</a>
<a href="#" class="item right">Log in</a>
</div>
</div>

View File

@ -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 <http://www.gnu.org/licenses/>.
#}
{% block electioncontent %}
<table class="ui celled table">
<thead>
<tr>
<th>Voter</th>
<th>Ballot fingerprint</th>
</tr>
</thead>
<tbody>
{% for voter in election.voters %}
<tr>
<td>{{ voter.name }}</td>
{% if voter.ballot|length > 0 %}
<td class="hash">{{ SHA256().update_obj(voter.ballot[-1]).hash_as_b64() }}</td>
{% else %}
<td class="hash"></td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -20,13 +20,17 @@
{% block title %}{{ election.name }}{% endblock %}
{% macro tab(name, view) %}
<a href="{{ url_for(view, election_id=election._id) }}" class="election-tab-ajax item{% if request.endpoint == view %} active{% endif %}">{{ name }}</a>
{% endmacro %}
{% block content %}
<h1>{{ election.name }}</h1>
<p><small><b>Election fingerprint:</b> <span class="hash">{{ SHA256().update_obj(election).hash_as_b64() }}</span></small></p>
<div class="ui secondary pointing menu" id="election-tab-menu">
<a href="#" class="election-tab-ajax item active">Overview</a>
{% include eosweb.core.main.model_view_map[election.__class__]['tabs'] %}
</div>
<div class="ui container" id="election-tab-content">
{% block electioncontent %}

View File

@ -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 <http://www.gnu.org/licenses/>.
#}
{% block title %}{{ election.name }} – Voting booth{% endblock %}
{% block content %}
<h1>{{ election.name }}</h1>
<p><small><b>Election fingerprint:</b> <span class="hash">{{ SHA256().update_obj(election).hash_as_b64() }}</span></small></p>
{% endblock %}

View File

@ -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 <http://www.gnu.org/licenses/>.
#}
{% block tabs %}
{{ tab('Overview', 'election_view') }}
{{ tab('Questions', 'election_view_questions') }}
{{ tab('Voters and ballots', 'election_view_ballots') }}
{% endblock %}

View File

@ -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 <http://www.gnu.org/licenses/>.
#}
{% block tabs %}
{{ super() }}
{{ tab('Trustees', 'election_view_trustees') }}
{% endblock %}

View File

@ -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 <http://www.gnu.org/licenses/>.
#}
{% block electioncontent %}
{% for question in election.questions %}
<h2>{{ loop.index }}. {{ question.prompt }}</h2>
{% include eosweb.core.main.model_view_map[question.__class__]['view'] %}
{% endfor %}
{% endblock %}

View File

@ -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 <http://www.gnu.org/licenses/>.
#}
{% block electioncontent %}
<h2>Mixing trustees</h2>
<ol class="ui list">
{% for trustee in election.mixing_trustees %}
<li>{{ trustee.name or 'Unnamed trustee' }}</li>
{% endfor %}
</ol>
{% endblock %}

View File

@ -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 %}
<p><a href="#" class="ui huge primary button">Click here to vote in this election</a></p>
{% if election.workflow.get_task('eos.base.workflow.TaskCloseVoting').status == Status.EXITED %}
<p><button class="ui huge button">Voting in this election has closed</button></p>
{% else %}
<p><a href="{{ url_for('election_booth', election_id=election._id) }}" class="ui huge primary button">Click here to vote in this election</a></p>
{% endif %}
{% else %}
<p><button class="ui huge button">Voting in this election has not yet opened</button></p>
{% endif %}

View File

@ -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 <http://www.gnu.org/licenses/>.
#}
<ul class="ui list">
{% for choice in question.choices %}
<li>{{ choice }}</li>
{% endfor %}
</ul>