#81 Drop the usernamemap
Merged 3 years ago by bcotton. Opened 4 years ago by pingou.
pingou/elections no_usernamemap  into  develop

@@ -83,9 +83,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."""

      return hasattr(flask.g, "fas_user") and flask.g.fas_user is not None
@@ -274,8 +271,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,

@@ -38,7 +38,6 @@ 

  )

  from fedora_elections import forms

  from fedora_elections import models

- from fedora_elections.utils import build_name_map

  

  import flask

  
@@ -145,14 +144,11 @@ 

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

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

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

-         ]

-     )

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

rebased onto f09cfaa

3 years ago

@pingou do we still need this? I notice your branch has disappeared. I can't remember if this was part of a fix for names not being displayed correctly or if it was just a cleanup of unused code.

rebased onto 4446d9a

3 years ago

Branch is back and PR is rebased :)

It's cleaning up of unused code.

Pull-Request has been merged by bcotton

3 years ago