From 4446d9aaba2d91a272730dfc3fa3d186bc41d038 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 09 2021 07:00:09 +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 bcc94c3..06f9cfb 100644 --- a/fedora_elections/__init__.py +++ b/fedora_elections/__init__.py @@ -83,9 +83,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.""" return hasattr(flask.g, "fas_user") and flask.g.fas_user is not None @@ -274,8 +271,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 84d984a..8ed8d35 100644 --- a/fedora_elections/elections.py +++ b/fedora_elections/elections.py @@ -38,7 +38,6 @@ from fedora_elections import ( ) from fedora_elections import forms from fedora_elections import models -from fedora_elections.utils import build_name_map import flask @@ -145,14 +144,11 @@ def election_results_text(election_alias): flask.flash("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 @@ -191,15 +187,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, ) @@ -248,15 +241,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 a9e2284..0000000 --- a/fedora_elections/utils.py +++ /dev/null @@ -1,14 +0,0 @@ -# -*- coding: utf-8 -*- - - -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 - ] - )