#80 Drop the usernamemap
Closed 4 years ago by pingou. Opened 4 years ago by pingou.
pingou/elections no_usernamemap  into  master

@@ -79,9 +79,6 @@ 

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

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

      return flask.render_template(

          'about.html',

          election=election,

-         usernamemap=usernamemap,

          stats=stats,

          voted=voted,

          evolution_label=evolution_label,

@@ -36,7 +36,6 @@ 

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

              "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 @@ 

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

                  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)

  

  

@@ -11,10 +11,9 @@ 

  </div>

  {% endmacro %}

  

- {% macro render_field_in_row(field, usernamemap=None, after="") %}

+ {% macro render_field_in_row(field, after="") %}

  <tr>

-     <td>{% if usernamemap %} {{ usernamemap[field.name] }} {%

-         else %} {{ field.label }} {% endif %}</td>

+     <td>{{ field.label }}</td>

      <td>{{ field(class_="c-select", **kwargs)|safe }}</td>

  {% if after %} <td>{{ after }}</td>{% endif %}

  {% if field.errors %}{% for error in field.errors
@@ -24,8 +23,7 @@ 

  

  {% macro render_bootstrap_textfield_in_row(field, after="", addon=None) %}

  <div class="form-group {% if field.errors %}has-danger{% endif %}">

-   {% if usernamemap %} {{ usernamemap[field.name] }} {%

-       else %} {{ field.label() }} {% endif %}

+       {{ field.label() }}

        {% if addon %}

        <div class="input-group">

        {% endif %}
@@ -45,8 +43,7 @@ 

  

  {% macro render_bootstrap_selectfield_in_row(field, after="") %}

  <div class="form-group {% if field.errors %}has-danger{% endif %}">

-   {% if usernamemap %} {{ usernamemap[field.name] }} {%

-       else %} {{ field.label() }} {% endif %}

+     {{ field.label() }}

      {{ field(class_="c-select fullwidth", **kwargs)|safe }}

      {% if after %} <div><small class="text-muted">{{ after }}</small></div>{% endif %}

      {% if field.errors %}
@@ -59,8 +56,7 @@ 

  

  {% macro render_bootstrap_checkbox_in_row(field, after="") %}

  <div class="form-group {% if field.errors %}has-danger{% endif %}">

-   {% if usernamemap %} {{ usernamemap[field.name] }} {%

-       else %} {{ field.label() }} {% endif %}

+      {{ field.label() }}

        <br/>

      {{ field(**kwargs)|safe }}

      {% if after %} <div><small class="text-muted">{{ after }}</small></div>{% endif %}
@@ -72,11 +68,9 @@ 

  </div>

  {% endmacro %}

  

- {% macro render_field_data_in_row(field, usernamemap=None, after="") %}

+ {% macro render_field_data_in_row(field, after="") %}

  <div class="list-group-item {% if field.errors %}has-danger list-group-item-danger{% endif %}">

-     {% 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 %} <div><small class="text-muted">{{ after }}</small></div>{% endif %}

        {% if field.errors %}

          {% for error in field.errors%}
@@ -86,7 +80,7 @@ 

  </div>

  {% endmacro %}

  

- {% macro render_radio_field_in_row(field, usernamemap=None, after="") %}

+ {% macro render_radio_field_in_row(field, after="") %}

  <div class="list-group-item {% if field.errors %}has-danger list-group-item-danger{% endif %}">

            {{ field(class_="pull-xs-right")}}

        {% if after %} <div><small class="text-muted">{{ after }}</small></div>{% endif %}

@@ -69,11 +69,7 @@ 

    <div class="list-group">

      {% for candidate in election.candidates %}

        <a {% if candidate.url %}href="{{ candidate.url }}" target="_blank" rel="noopener noreferrer"{%endif%} class="list-group-item">

-           {% 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 %}

        </a>

      {% endfor %}
@@ -150,11 +146,7 @@ 

              {% if candidate.url %}

                <a href="{{ 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 %}

                </a>

              {% endif %}

@@ -52,9 +52,7 @@ 

    {%- 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 %}

  

  

@@ -18,8 +18,7 @@ 

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

      <form action="{{ url_for('vote', election_alias=election.alias) }}" method="post">

          {% 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 %}

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

-     ])

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 pingou@pingoured.fr

Pull-Request has been closed by pingou

4 years ago