diff --git a/management/views.py b/management/views.py index 7cf1c07f6b7c24c338ecf1651dc97366442aa5f4..795a8e0efd79c78f6f86537fa091cd63ca73bb05 100644 --- a/management/views.py +++ b/management/views.py @@ -61,7 +61,8 @@ def index(request): manager = request.user if request.GET.get("action") == "add_session": - form = AddSessionForm(request=request, user=request.user, data=request.POST or None) + form = AddSessionForm( + request=request, user=request.user, data=request.POST or None) if request.POST and form.is_valid(): if request.POST.get("submit_type") != "test": @@ -71,7 +72,8 @@ def index(request): messages.add_message(request, messages.INFO, 'Test email sent.') Voter.send_test_invitation( title=form.cleaned_data['title'], - start_date=form.cleaned_data['start_date'] if form.cleaned_data['start_date'] else timezone.now(), + start_date=form.cleaned_data['start_date'] if form.cleaned_data['start_date'] else timezone.now( + ), meeting_link=form.cleaned_data['meeting_link'], invite_text=form.cleaned_data['invite_text'], to_email=form.cleaned_data['email'], @@ -108,14 +110,17 @@ def session_settings(request, pk=None): manager = request.user session = manager.sessions.get(pk=pk) - form = SessionSettingsForm(instance=session, request=request, user=request.user, data=request.POST or None) + form = SessionSettingsForm( + instance=session, request=request, user=request.user, data=request.POST or None) if request.POST: if form.is_valid(): if request.POST.get("submit_type") == "test": - messages.add_message(request, messages.INFO, 'Test email sent.') + messages.add_message( + request, messages.INFO, 'Test email sent.') Voter.send_test_invitation( title=form.cleaned_data['title'], - start_date=form.cleaned_data['start_date'] if form.cleaned_data['start_date'] else timezone.now(), + start_date=form.cleaned_data['start_date'] if form.cleaned_data['start_date'] else timezone.now( + ), meeting_link=form.cleaned_data['meeting_link'], invite_text=form.cleaned_data['invite_text'], to_email=form.cleaned_data['email'], @@ -123,7 +128,8 @@ def session_settings(request, pk=None): ) else: form.save() - messages.add_message(request, messages.INFO, 'Session updated successfully!') + messages.add_message(request, messages.INFO, + 'Session updated successfully!') return redirect('management:session', session.id) context = { @@ -144,7 +150,8 @@ def add_election(request, pk=None): 'session': session, } - form = AddElectionForm(session=session, request=request, user=manager, data=request.POST if request.POST else None) + form = AddElectionForm(session=session, request=request, + user=manager, data=request.POST if request.POST else None) context['form'] = form context['variables'] = form.variables if request.POST and form.is_valid(): @@ -163,7 +170,8 @@ def add_election(request, pk=None): "end_date": form.cleaned_data['end_date'], }) - Voter.send_reminder(test_voter, manager.sender_email, test_election) + Voter.send_reminder( + test_voter, manager.sender_email, test_election) else: form.save() return redirect('management:session', pk=session.pk) @@ -179,7 +187,8 @@ def add_voters(request, pk): 'session': session, 'form': AddVotersForm(session=session) } - form = AddVotersForm(session=session, data=request.POST if request.POST else None) + form = AddVotersForm( + session=session, data=request.POST if request.POST else None) context['form'] = form if request.POST and form.is_valid(): form.save() @@ -196,7 +205,8 @@ def add_tokens(request, pk): 'session': session, 'form': AddTokensForm(session=session) } - form = AddTokensForm(session=session, data=request.POST if request.POST else None) + form = AddTokensForm( + session=session, data=request.POST if request.POST else None) context['form'] = form if request.POST and form.is_valid(): form.save() @@ -238,7 +248,8 @@ def election_detail(request, pk): form.save() if election.send_emails_on_start: for voter in session.participants.all(): - voter.send_reminder(session.managers.all().first().sender_email, election) + voter.send_reminder( + session.managers.all().first().sender_email, election) else: context['start_election_form'] = form @@ -254,7 +265,8 @@ def election_upload_application(request, pk, application_id=None): _, election, _ = _unpack(request, pk) if not election.can_apply: - messages.add_message(request, messages.ERROR, 'Applications are currently not accepted') + messages.add_message(request, messages.ERROR, + 'Applications are currently not accepted') return redirect('management:election', pk=pk) if application_id: @@ -268,7 +280,8 @@ def election_upload_application(request, pk, application_id=None): if request.method == 'GET': form = ApplicationUploadForm(election, request, instance=instance) else: - form = ApplicationUploadForm(election, request, data=request.POST, files=request.FILES, instance=instance) + form = ApplicationUploadForm( + election, request, data=request.POST, files=request.FILES, instance=instance) if form.is_valid(): form.save() return redirect('management:election', election.pk) @@ -339,9 +352,11 @@ def print_token(request, pk): return HttpResponseNotFound('Session does not exist') session = session.first() participants = session.participants - tokens = [participant.new_access_token() for participant in participants.all() if participant.is_anonymous] + tokens = [participant.new_access_token() + for participant in participants.all() if participant.is_anonymous] if len(tokens) == 0: - messages.add_message(request, messages.ERROR, 'No tokens have yet been generated.') + messages.add_message(request, messages.ERROR, + 'No tokens have yet been generated.') return redirect('management:session', pk=session.pk) img = [qrcode.make(f'https://{settings.URL}' + reverse('vote:link_login', kwargs={'access_code': access_code})) @@ -359,7 +374,8 @@ def print_token(request, pk): path_i = os.path.join(tmp_qr_path, 'qr_{}.png'.format(idx)) i.save(path_i) paths.append(path_i) - zipped = [{'path': path, 'token': token} for path, token in zip(paths, tokens)] + zipped = [{'path': path, 'token': token} + for path, token in zip(paths, tokens)] context = { 'session': session, 'tokens': zipped, @@ -378,7 +394,8 @@ def generate_pdf(template_name: str, context: Dict, tex_path: str): template = get_template(template_name).render(context).encode('utf8') with open("/tmp/template.tex", "wb") as f: f.write(template) - pdf = PdfLatexBuilder(pdflatex='pdflatex').build_pdf(template, texinputs=[tex_path, '']) + pdf = PdfLatexBuilder(pdflatex='pdflatex').build_pdf( + template, texinputs=[tex_path, '']) return pdf diff --git a/vote/templates/vote/index.html b/vote/templates/vote/index.html index 2435d842920f8b713c5f5ecd073ba8708a01ddee..30bd8a6ecebea75dceef6c3a72bb0b14119c6e6c 100644 --- a/vote/templates/vote/index.html +++ b/vote/templates/vote/index.html @@ -2,80 +2,80 @@ {% load static %} {% block content %} - <div class="row justify-content-center"> +<div class="row justify-content-center"> - <div class="col-12"> - <div class="card bg-dark text-light shadow mb-2 py-2"> + <div class="col-12"> + <div class="card bg-dark text-light shadow mb-2 py-2"> + <div class="card-body"> + <h4 class="text-center d-inline">{{ title }}</h4> + {% if meeting_link %} + <div><small>Meeting at <a href="{{ meeting_link }}">{{ meeting_link }}</a></small></div> + {% endif %} + </div> + </div> + <div id="electionCard"> + {% if not existing_elections %} + <div class="list-group-item mt-3"> + <span>There are no elections for this session</span> + </div> + {% elif open_elections %} + <div class="card shadow mb-2"> + <div class="card-header"> + <h4>Open Elections</h4> + </div> <div class="card-body"> - <h4 class="text-center d-inline">{{ title }}</h4> - {% if meeting_link %} - <div><small>Meeting at <a href="{{ meeting_link }}">{{ meeting_link }}</a></small></div> - {% endif %} + {% for election, can_vote, edit in open_elections %} + {% include 'vote/index_election_item.html' %} + {% endfor %} </div> </div> - <div id="electionCard"> - {% if not existing_elections %} - <div class="list-group-item mt-3"> - <span>There are no elections for this session</span> - </div> - {% elif open_elections %} - <div class="card shadow mb-2"> - <div class="card-header"> - <h4>Open Elections</h4> - </div> - <div class="card-body"> - {% for election, can_vote, edit in open_elections %} - {% include 'vote/index_election_item.html' %} - {% endfor %} - </div> - </div> - {% endif %} - {% if upcoming_elections %} - <div class="card shadow mb-2"> - <div class="card-header"> - <h4>Upcoming Elections</h4> - </div> - <div class="card-body"> - {% for election, can_vote, edit in upcoming_elections %} - {% include 'vote/index_election_item.html' %} - {% endfor %} - </div> - </div> - {% endif %} - {% if published_elections %} - <div class="card shadow mb-2"> - <div class="card-header"> - <h4>Published Results</h4> - </div> - <div class="card-body"> - {% for election, can_vote, edit in published_elections %} - {% include 'vote/index_election_item.html' %} - {% endfor %} - </div> - </div> - {% endif %} - {% if closed_elections %} - <div class="card shadow mb-2"> - <div class="card-header"> - <h4>Closed Elections</h4> - </div> - <div class="card-body"> - {% for election, can_vote, edit in closed_elections %} - {% include 'vote/index_election_item.html' %} - {% endfor %} - </div> - </div> - {% endif %} + {% endif %} + {% if upcoming_elections %} + <div class="card shadow mb-2"> + <div class="card-header"> + <h4>Upcoming Elections</h4> + </div> + <div class="card-body"> + {% for election, can_vote, edit in upcoming_elections %} + {% include 'vote/index_election_item.html' %} + {% endfor %} + </div> + </div> + {% endif %} + {% if published_elections %} + <div class="card shadow mb-2"> + <div class="card-header"> + <h4>Published Results</h4> + </div> + <div class="card-body"> + {% for election, can_vote, edit in published_elections %} + {% include 'vote/index_election_item.html' %} + {% endfor %} + </div> </div> + {% endif %} + {% if closed_elections %} + <div class="card shadow mb-2"> + <div class="card-header"> + <h4>Closed Elections</h4> + </div> + <div class="card-body"> + {% for election, can_vote, edit in closed_elections %} + {% include 'vote/index_election_item.html' %} + {% endfor %} + </div> + </div> + {% endif %} </div> </div> +</div> {% endblock %} {% block footer_scripts %} - {# Automatic reload of the page: #} - {# - either if the start date / end date of a election is due#} - {# - or if the admin started / stopped one election and the page is notified with a websocket#} - <script src="{% static "js/jquery-3.5.1.min.js" %}" - integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="></script> - <script src="{% static "js/reload.js" %}"></script> -{% endblock %} +{# Automatic reload of the page: #} +{# - either if the start date / end date of a election is due#} +{# - or if the admin started / stopped one election and the page is notified with a websocket#} +<script src="{% static " js/jquery-3.5.1.min.js" %}" + integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="></script> +<script src="{% static " js/reload.js" %}"></script> +{% endblock %} \ No newline at end of file diff --git a/vote/templates/vote/spectator.html b/vote/templates/vote/spectator.html index 79c2085d9d57427dcd99272d3eda36d2015c9830..2c8accf3749f3e0e1dd12e332f5753b1583d3896 100644 --- a/vote/templates/vote/spectator.html +++ b/vote/templates/vote/spectator.html @@ -3,80 +3,80 @@ {% load vote_extras %} {% block content %} - <div class="row justify-content-center"> +<div class="row justify-content-center"> - <div class="col-12"> - <div class="card bg-dark text-light shadow mb-2 py-2"> + <div class="col-12"> + <div class="card bg-dark text-light shadow mb-2 py-2"> + <div class="card-body"> + <h4 class="text-center d-inline">{{ title }} - Spectator View</h4> + {% if meeting_link %} + <div><small>Meeting at <a href="{{ meeting_link }}">{{ meeting_link }}</a></small></div> + {% endif %} + </div> + </div> + <div id="electionCard"> + {% if not existing_elections %} + <div class="list-group-item mt-3"> + <span>There are no elections for this session</span> + </div> + {% elif open_elections %} + <div class="card shadow mb-2"> + <div class="card-header"> + <h4>Open Elections</h4> + </div> <div class="card-body"> - <h4 class="text-center d-inline">{{ title }} - Spectator View</h4> - {% if meeting_link %} - <div><small>Meeting at <a href="{{ meeting_link }}">{{ meeting_link }}</a></small></div> - {% endif %} + {% for election in open_elections %} + {% include 'vote/spectator_election_item.html' %} + {% endfor %} </div> </div> - <div id="electionCard"> - {% if not existing_elections %} - <div class="list-group-item mt-3"> - <span>There are no elections for this session</span> - </div> - {% elif open_elections %} - <div class="card shadow mb-2"> - <div class="card-header"> - <h4>Open Elections</h4> - </div> - <div class="card-body"> - {% for election in open_elections %} - {% include 'vote/spectator_election_item.html' %} - {% endfor %} - </div> - </div> - {% endif %} - {% if upcoming_elections %} - <div class="card shadow mb-2"> - <div class="card-header"> - <h4>Upcoming Elections</h4> - </div> - <div class="card-body"> - {% for election in upcoming_elections %} - {% include 'vote/spectator_election_item.html' %} - {% endfor %} - </div> - </div> - {% endif %} - {% if published_elections %} - <div class="card shadow mb-2"> - <div class="card-header"> - <h4>Published Results</h4> - </div> - <div class="card-body"> - {% for election in published_elections %} - {% include 'vote/spectator_election_item.html' %} - {% endfor %} - </div> - </div> - {% endif %} - {% if closed_elections %} - <div class="card shadow mb-2"> - <div class="card-header"> - <h4>Closed Elections</h4> - </div> - <div class="card-body"> - {% for election in closed_elections %} - {% include 'vote/spectator_election_item.html' %} - {% endfor %} - </div> - </div> - {% endif %} + {% endif %} + {% if upcoming_elections %} + <div class="card shadow mb-2"> + <div class="card-header"> + <h4>Upcoming Elections</h4> + </div> + <div class="card-body"> + {% for election in upcoming_elections %} + {% include 'vote/spectator_election_item.html' %} + {% endfor %} + </div> + </div> + {% endif %} + {% if published_elections %} + <div class="card shadow mb-2"> + <div class="card-header"> + <h4>Published Results</h4> + </div> + <div class="card-body"> + {% for election in published_elections %} + {% include 'vote/spectator_election_item.html' %} + {% endfor %} + </div> </div> + {% endif %} + {% if closed_elections %} + <div class="card shadow mb-2"> + <div class="card-header"> + <h4>Closed Elections</h4> + </div> + <div class="card-body"> + {% for election in closed_elections %} + {% include 'vote/spectator_election_item.html' %} + {% endfor %} + </div> + </div> + {% endif %} </div> </div> +</div> {% endblock %} {% block footer_scripts %} - {# Automatic reload of the page: #} - {# - either if the start date / end date of a election is due#} - {# - or if the admin started / stopped one election and the page is notified with a websocket#} - <script src="{% static "js/jquery-3.5.1.min.js" %}" - integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="></script> - <script src="{% static "js/reload.js" %}"></script> -{% endblock %} +{# Automatic reload of the page: #} +{# - either if the start date / end date of a election is due#} +{# - or if the admin started / stopped one election and the page is notified with a websocket#} +<script src="{% static " js/jquery-3.5.1.min.js" %}" + integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="></script> +<script src="{% static " js/reload.js" %}"></script> +{% endblock %} \ No newline at end of file diff --git a/vote/views.py b/vote/views.py index d5774cb2014a329ded6f16d726bf6b3880ee7e2a..a4f78698e3bf73cc02af948f0a6cf780562a41db 100644 --- a/vote/views.py +++ b/vote/views.py @@ -92,7 +92,8 @@ def vote(request, election_id): can_vote = voter.can_vote(election) if election.max_votes_yes is not None: - max_votes_yes = min(election.max_votes_yes, election.applications.all().count()) + max_votes_yes = min(election.max_votes_yes, + election.applications.all().count()) else: max_votes_yes = election.applications.all().count() @@ -133,7 +134,8 @@ def apply(request, election_id): if request.method == 'GET': form = ApplicationUploadFormUser(election, request, instance=instance) else: - form = ApplicationUploadFormUser(election, request, data=request.POST, files=request.FILES, instance=instance) + form = ApplicationUploadFormUser( + election, request, data=request.POST, files=request.FILES, instance=instance) if form.is_valid(): form.save() return redirect('vote:index') @@ -153,7 +155,8 @@ def delete_own_application(request, election_id): election = get_object_or_404(voter.session.elections, pk=election_id) application = voter.applications.filter(election__id=election_id) if not election.can_apply: - messages.add_message(request, messages.ERROR, 'Applications can currently not be deleted') + messages.add_message(request, messages.ERROR, + 'Applications can currently not be deleted') return redirect('vote:index') if application.exists(): instance = application.first()