|
@@ -3,14 +3,8 @@
|
|
Authentication module
|
|
Authentication module
|
|
"""
|
|
"""
|
|
|
|
|
|
-import hashlib
|
|
|
|
-import hmac
|
|
|
|
-
|
|
|
|
-from datetime import datetime
|
|
|
|
-from flask_login import login_required, current_user
|
|
|
|
-from flask_menu import Menu, register_menu
|
|
|
|
from flask import render_template, request, flash, Blueprint, redirect, url_for
|
|
from flask import render_template, request, flash, Blueprint, redirect, url_for
|
|
-from app.models import User, Page, Ballot, Priority, Question, Option, Vote, Code
|
|
|
|
|
|
+from app.models import User, Ballot, Question, Option, Vote, Code
|
|
from app import db
|
|
from app import db
|
|
|
|
|
|
|
|
|
|
@@ -20,127 +14,19 @@ BLUEPRINT = Blueprint(
|
|
template_folder='templates'
|
|
template_folder='templates'
|
|
)
|
|
)
|
|
|
|
|
|
-@register_menu(BLUEPRINT, 'vote', 'Vote')
|
|
|
|
-@BLUEPRINT.route("/")
|
|
|
|
-@login_required
|
|
|
|
-def main():
|
|
|
|
- """Ballots overview"""
|
|
|
|
- ballots = Ballot.query.all()
|
|
|
|
-
|
|
|
|
- return render_template(
|
|
|
|
- 'main.j2',
|
|
|
|
- ballots=ballots,
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@BLUEPRINT.route("/codes")
|
|
|
|
-@login_required
|
|
|
|
-def codes():
|
|
|
|
- """codes overview"""
|
|
|
|
- code = Code.query.order_by(Code.expire_date.desc()).first()
|
|
|
|
- users = User.query.all()
|
|
|
|
-
|
|
|
|
- return render_template(
|
|
|
|
- 'vote/codes.j2',
|
|
|
|
- users=users,
|
|
|
|
- code=code,
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@BLUEPRINT.route('/create', methods=["GET", "POST"])
|
|
|
|
-@login_required
|
|
|
|
-def create():
|
|
|
|
- """Creating ballot"""
|
|
|
|
- if request.method == 'POST':
|
|
|
|
- ballot = Ballot()
|
|
|
|
- print(request.form)
|
|
|
|
- ballot.name = request.form['name']
|
|
|
|
- ballot.description = request.form['description']
|
|
|
|
- ballot.user_id = current_user.id
|
|
|
|
-
|
|
|
|
- start_at = "%s %s" % (request.form['start_at_date'], request.form['start_at_time'])
|
|
|
|
- ballot.start_at = datetime.strptime(start_at, "%Y-%m-%d %H:%M")
|
|
|
|
- end_at = "%s %s" % (request.form['end_at_date'], request.form['end_at_time'])
|
|
|
|
- ballot.end_at = datetime.strptime(end_at, "%Y-%m-%d %H:%M")
|
|
|
|
-
|
|
|
|
- db.session.add(ballot)
|
|
|
|
- db.session.commit()
|
|
|
|
-
|
|
|
|
- flash('Page "%s" successfully created' % ballot.name, 'success')
|
|
|
|
- return redirect(url_for('vote.view', ballot_id=ballot.id))
|
|
|
|
-
|
|
|
|
- priorities = Priority.query.all()
|
|
|
|
-
|
|
|
|
- return render_template(
|
|
|
|
- 'vote/create.j2',
|
|
|
|
- priorities=priorities
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@BLUEPRINT.route('/<int:ballot_id>', methods=["GET", "POST"])
|
|
|
|
-@login_required
|
|
|
|
-def view(ballot_id):
|
|
|
|
- """View ballot"""
|
|
|
|
- ballot = Ballot.query.get(ballot_id)
|
|
|
|
- if request.method == 'POST':
|
|
|
|
- option = Option()
|
|
|
|
- option.question_id = request.form['question_id']
|
|
|
|
- option.name = request.form['name']
|
|
|
|
-
|
|
|
|
- db.session.add(option)
|
|
|
|
- db.session.commit()
|
|
|
|
-
|
|
|
|
- return render_template(
|
|
|
|
- 'vote/view.j2',
|
|
|
|
- ballot=ballot,
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@BLUEPRINT.route('/<int:ballot_id>/add_question', methods=["GET", "POST"])
|
|
|
|
-@login_required
|
|
|
|
-def add_question(ballot_id):
|
|
|
|
- """Add question to ballot"""
|
|
|
|
- ballot = Ballot.query.get(ballot_id)
|
|
|
|
- if request.method == 'POST':
|
|
|
|
- question = Question()
|
|
|
|
- question.ballot_id = ballot.id
|
|
|
|
- question.name = request.form['name']
|
|
|
|
- question.description = request.form['description']
|
|
|
|
- question.combined_approval_voting = 'combined_approval_voting' in request.form
|
|
|
|
-
|
|
|
|
- db.session.add(question)
|
|
|
|
- db.session.commit()
|
|
|
|
-
|
|
|
|
- if question.combined_approval_voting:
|
|
|
|
- options = ['Voor', 'Tegen', 'Onthouden']
|
|
|
|
- for option_name in options:
|
|
|
|
- option = Option()
|
|
|
|
- option.question_id = question.id
|
|
|
|
- option.name = option_name
|
|
|
|
-
|
|
|
|
- db.session.add(option)
|
|
|
|
-
|
|
|
|
- db.session.commit()
|
|
|
|
- return redirect(url_for('vote.view', ballot_id=ballot.id))
|
|
|
|
-
|
|
|
|
- return render_template(
|
|
|
|
- 'vote/add_question.j2',
|
|
|
|
- ballot=ballot,
|
|
|
|
- )
|
|
|
|
|
|
|
|
-
|
|
|
|
-@BLUEPRINT.route('/public/')
|
|
|
|
|
|
+@BLUEPRINT.route('/')
|
|
def public_index():
|
|
def public_index():
|
|
"""View list of votes"""
|
|
"""View list of votes"""
|
|
ballots = Ballot.query.all()
|
|
ballots = Ballot.query.all()
|
|
|
|
|
|
return render_template(
|
|
return render_template(
|
|
- 'vote/public/index.j2',
|
|
|
|
|
|
+ 'vote/index.j2',
|
|
ballots=ballots,
|
|
ballots=ballots,
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
-@BLUEPRINT.route('/public/<int:ballot_id>', methods=["GET", "POST"])
|
|
|
|
|
|
+@BLUEPRINT.route('/<int:ballot_id>', methods=["GET", "POST"])
|
|
def public_view(ballot_id):
|
|
def public_view(ballot_id):
|
|
"""Vote and view results of ballot"""
|
|
"""Vote and view results of ballot"""
|
|
ballot = Ballot.query.get(ballot_id)
|
|
ballot = Ballot.query.get(ballot_id)
|
|
@@ -160,7 +46,7 @@ def public_view(ballot_id):
|
|
question = Question.query.get(question_id)
|
|
question = Question.query.get(question_id)
|
|
if question.has_voten(user_id):
|
|
if question.has_voten(user_id):
|
|
flash('Je hebt al gestemd.', 'warning')
|
|
flash('Je hebt al gestemd.', 'warning')
|
|
- return redirect(url_for('vote.view', ballot_id=ballot.id))
|
|
|
|
|
|
+ return redirect(url_for('backend_backend_vote.view', ballot_id=ballot.id))
|
|
|
|
|
|
option = question.options.filter(Option.id == option_id).first()
|
|
option = question.options.filter(Option.id == option_id).first()
|
|
|
|
|
|
@@ -175,6 +61,6 @@ def public_view(ballot_id):
|
|
flash('Fout in veiligheids code.', 'warning')
|
|
flash('Fout in veiligheids code.', 'warning')
|
|
|
|
|
|
return render_template(
|
|
return render_template(
|
|
- 'vote/public/view.j2',
|
|
|
|
|
|
+ 'vote/view.j2',
|
|
ballot=ballot,
|
|
ballot=ballot,
|
|
)
|
|
)
|