From e1c4835b2a144a62667bec8b933ddd3c44fa4a9d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 19 2019 09:14:57 +0000 Subject: Drop the usernamemap This map was built and used at the time we did not store the candidate's real username in the database when registering the candidate for the election. Now that we do this, this usernamemap is no longer useful or necessary and actually kinda confusing Signed-off-by: Pierre-Yves Chibon --- diff --git a/fedora_elections/__init__.py b/fedora_elections/__init__.py index 20e7865..80b403f 100644 --- a/fedora_elections/__init__.py +++ b/fedora_elections/__init__.py @@ -79,9 +79,6 @@ SESSION = models.create_session(APP.config['DB_URL']) from fedora_elections import forms # noqa -from fedora_elections.utils import build_name_map # noqa - - def is_authenticated(): ''' Return a boolean specifying if the user is authenticated or not. ''' @@ -275,8 +272,6 @@ def about_election(election_alias): evolution_data.append([cnt, stats['vote_timestamps'].count(day)]) cnt += 1 - usernamemap = build_name_map(election) - voted = [] if is_authenticated(): votes = models.Vote.of_user_on_election( @@ -287,7 +282,6 @@ def about_election(election_alias): return flask.render_template( 'about.html', election=election, - usernamemap=usernamemap, stats=stats, voted=voted, evolution_label=evolution_label, diff --git a/fedora_elections/elections.py b/fedora_elections/elections.py index a4c98c7..bb74ebe 100644 --- a/fedora_elections/elections.py +++ b/fedora_elections/elections.py @@ -36,7 +36,6 @@ from fedora_elections import ( OIDC, APP, SESSION, is_authenticated, is_admin, is_election_admin, safe_redirect_back, ) -from fedora_elections.utils import build_name_map def login_required(f): @@ -136,14 +135,11 @@ def election_results_text(election_alias): "The text results are only available to the admins", "error") return safe_redirect_back() - usernamemap = build_name_map(election) - stats = models.Vote.get_election_stats(SESSION, election.id) return flask.render_template( 'results_text.html', election=election, - usernamemap=usernamemap, stats=stats, candidates=sorted( election.candidates, key=lambda x: x.vote_count, reverse=True) @@ -181,15 +177,12 @@ def vote_range(election, revote): flask.flash("Please confirm your vote!") next_action = 'vote' - usernamemap = build_name_map(election) - return flask.render_template( 'vote_range.html', election=election, form=form, num_candidates=num_candidates, max_range=max_selection, - usernamemap=usernamemap, nextaction=next_action) @@ -237,15 +230,12 @@ def vote_select(election, revote): flask.flash("Please confirm your vote!") next_action = 'vote' - usernamemap = build_name_map(election) - return flask.render_template( 'vote_simple.html', election=election, form=form, num_candidates=num_candidates, max_selection=max_selection, - usernamemap=usernamemap, nextaction=next_action) diff --git a/fedora_elections/templates/_formhelpers.html b/fedora_elections/templates/_formhelpers.html index 0683977..1d093c7 100644 --- a/fedora_elections/templates/_formhelpers.html +++ b/fedora_elections/templates/_formhelpers.html @@ -11,10 +11,9 @@ {% endmacro %} -{% macro render_field_in_row(field, usernamemap=None, after="") %} +{% macro render_field_in_row(field, after="") %} - {% if usernamemap %} {{ usernamemap[field.name] }} {% - else %} {{ field.label }} {% endif %} + {{ field.label }} {{ field(class_="c-select", **kwargs)|safe }} {% if after %} {{ after }}{% endif %} {% if field.errors %}{% for error in field.errors @@ -24,8 +23,7 @@ {% macro render_bootstrap_textfield_in_row(field, after="", addon=None) %}
- {% if usernamemap %} {{ usernamemap[field.name] }} {% - else %} {{ field.label() }} {% endif %} + {{ field.label() }} {% if addon %}
{% endif %} @@ -45,8 +43,7 @@ {% macro render_bootstrap_selectfield_in_row(field, after="") %}
- {% if usernamemap %} {{ usernamemap[field.name] }} {% - else %} {{ field.label() }} {% endif %} + {{ field.label() }} {{ field(class_="c-select fullwidth", **kwargs)|safe }} {% if after %}
{{ after }}
{% endif %} {% if field.errors %} @@ -59,8 +56,7 @@ {% macro render_bootstrap_checkbox_in_row(field, after="") %}
- {% if usernamemap %} {{ usernamemap[field.name] }} {% - else %} {{ field.label() }} {% endif %} + {{ field.label() }}
{{ field(**kwargs)|safe }} {% if after %}
{{ after }}
{% endif %} @@ -72,11 +68,9 @@
{% endmacro %} -{% macro render_field_data_in_row(field, usernamemap=None, after="") %} +{% macro render_field_data_in_row(field, after="") %}
- {% if usernamemap %} {{ usernamemap[field.name] }} {% - else %} {{ field.label }} {% endif %} - {{ field(class_="c-select pull-xs-right")}} + {{ field.label }} {{ field(class_="c-select pull-xs-right")}} {% if after %}
{{ after }}
{% endif %} {% if field.errors %} {% for error in field.errors%} @@ -86,7 +80,7 @@
{% endmacro %} -{% macro render_radio_field_in_row(field, usernamemap=None, after="") %} +{% macro render_radio_field_in_row(field, after="") %}
{{ field(class_="pull-xs-right")}} {% if after %}
{{ after }}
{% endif %} diff --git a/fedora_elections/templates/about.html b/fedora_elections/templates/about.html index de10caa..bfd24dc 100644 --- a/fedora_elections/templates/about.html +++ b/fedora_elections/templates/about.html @@ -69,11 +69,7 @@
{% for candidate in election.candidates %} - {% if election.candidates_are_fasusers %} - {{ usernamemap['%s' % candidate.id] }} - {% else %} - {{ candidate.name }} - {% endif %} + {{ candidate.fas_name or candidate.name }} {% if candidate.url %}(click for more info){% endif %} {% endfor %} @@ -150,11 +146,7 @@ {% if candidate.url %} {% endif %} - {% if election.candidates_are_fasusers %} - {{ usernamemap['%s' % candidate.id] }} - {% else %} - {{candidate.name}} - {% endif %} + {{ candidate.fas_name or candidate.name }} {% if candidate.url %} {% endif %} diff --git a/fedora_elections/templates/results_text.html b/fedora_elections/templates/results_text.html index 14f9503..255827f 100644 --- a/fedora_elections/templates/results_text.html +++ b/fedora_elections/templates/results_text.html @@ -52,9 +52,7 @@ The results for the elections are as follows: {%- if lastrow[-1] == 1 %} - --------+---------------------- {%- endif %} -{{ candidate.vote_count | rjust(8) }} | {% if election.candidates_are_fasusers -%} - {{ usernamemap[candidate.id] }} {%- else -%} {{candidate.name}} - {%- endif %} +{{ candidate.vote_count | rjust(8) }} | {{ candidate.fas_name or candidate.name }} {%- endfor %} diff --git a/fedora_elections/templates/vote_range.html b/fedora_elections/templates/vote_range.html index ade038b..78ef4bd 100644 --- a/fedora_elections/templates/vote_range.html +++ b/fedora_elections/templates/vote_range.html @@ -18,8 +18,7 @@

Here are the candidates for the {{ election.seats_elected }} seat(s) open:

{% for field in form if field.widget.input_type != 'hidden' %} - {{ render_field_data_in_row( - field, usernamemap=usernamemap) }} + {{ render_field_data_in_row(field) }} {% endfor %} {% if g.fas_user %} diff --git a/fedora_elections/utils.py b/fedora_elections/utils.py deleted file mode 100644 index 0d50999..0000000 --- a/fedora_elections/utils.py +++ /dev/null @@ -1,13 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals, absolute_import - - -def build_name_map(election): - """ Returns a mapping of candidate ids to fas human_names. """ - if not election.candidates_are_fasusers: - return {} - - return dict([ - (str(candidate.id), candidate.fas_name or candidate.name) - for candidate in election.candidates - ])