#66 Small fixes
Merged 5 years ago by pingou. Opened 5 years ago by pingou.

file modified
+15 -15
@@ -1,6 +1,6 @@ 

  from __future__ import with_statement

  from alembic import context

- from sqlalchemy import engine_from_config, pool

+ from sqlalchemy import create_engine, pool

  from logging.config import fileConfig

  

  # this is the Alembic Config object, which provides
@@ -11,17 +11,24 @@ 

  # This line sets up loggers basically.

  fileConfig(config.config_file_name)

  

+ import fedora_elections

+ import fedora_elections.models

+ 

  # add your model's MetaData object here

  # for 'autogenerate' support

  # from myapp import mymodel

  # target_metadata = mymodel.Base.metadata

- target_metadata = None

+ target_metadata = fedora_elections.models.BASE

  

  # other values from the config, defined by the needs of env.py,

  # can be acquired:

  # my_important_option = config.get_main_option("my_important_option")

  # ... etc.

  

+ DBURL = config.get_main_option("sqlalchemy.url")

+ if not DBURL:

+     DBURL = fedora_elections.APP.config['DB_URL']

+ 

  

  def run_migrations_offline():

      """Run migrations in 'offline' mode.
@@ -35,8 +42,7 @@ 

      script output.

  

      """

-     url = config.get_main_option("sqlalchemy.url")

-     context.configure(url=url)

+     context.configure(url=DBURL, target_metadata=target_metadata)

  

      with context.begin_transaction():

          context.run_migrations()
@@ -49,21 +55,15 @@ 

      and associate a connection with the context.

  

      """

-     engine = engine_from_config(

-         config.get_section(config.config_ini_section),

-         prefix='sqlalchemy.',

-         poolclass=pool.NullPool)

+     connectable = create_engine(DBURL, poolclass=pool.NullPool)

  

-     connection = engine.connect()

-     context.configure(

-         connection=connection,

-         target_metadata=target_metadata)

+     with connectable.connect() as connection:

+         context.configure(

+             connection=connection,

+             target_metadata=target_metadata)

  

-     try:

          with context.begin_transaction():

              context.run_migrations()

-     finally:

-         connection.close()

  

  

  if context.is_offline_mode():

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

      """ Add the url_badge column to the Elections table. """

      op.add_column(

          'elections',

-         sa.Column('voted_badge', sa.Unicode(250), nullable=True)

+         sa.Column('url_badge', sa.Unicode(250), nullable=True)

      )

  

  

file modified
+1 -8
@@ -330,14 +330,7 @@ 

      if not next_url or next_url == flask.url_for('.auth_login'):

          next_url = flask.url_for('.index')

  

-     if hasattr(flask.g, 'fas_user') and flask.g.fas_user is not None:

-         return safe_redirect_back(next_url)

-     else:

-         groups = APP.config['FEDORA_ELECTIONS_ADMIN_GROUP'][:]

-         if isinstance(groups, basestring):

-             groups = [groups]

-         groups.extend(models.get_groups(SESSION))

-         return flask.redirect(next_url)

+     return safe_redirect_back(next_url)

  

  

  @APP.route('/logout')

@@ -0,0 +1,10 @@ 

+ {% if election.url_badge %}

+ <div class="alert alert-dismissable fade in alert-info">

+   <button type="button" class="close" data-dismiss="alert" aria-label="Close">

+     <span aria-hidden="true">&times;</span>

+   </button>

+   <span class="col-md-offset-3">

+     Do not forget to <a href="{{election.url_badge}}">claim your badge</a>!

+   </span>

+ </div>

+ {% endif %}

@@ -111,7 +111,7 @@ 

              <p class="text-muted credit">

           Copyright © 2013-2016 Red Hat

              </p>

-             <p class="text-muted credit"> Powered by the <a href="//github.com/fedora-infra/elections/"

+             <p class="text-muted credit"> Powered by the <a href="https://pagure.io/elections/"

                    target="_blank">elections</a> app -- version {{ version }}</p>

          </div>

      </div>

@@ -2,35 +2,42 @@ 

  

  {% extends "base.html" %}

  {% block body %}

+ 

+ {% if nextaction == 'vote' %}

+ {% include "_claim_badge_page.html" %}

+ {% endif %}

+ 

  <div class="row">

- <div class="col-md-6 col-md-offset-3 voting-sheet">

- <h1 class="text-xs-center"><strong>{{election.shortdesc}}</strong></h1>

+   <div class="col-md-6 col-md-offset-3 voting-sheet">

+     <h1 class="text-xs-center"><strong>{{election.shortdesc}}</strong></h1>

  

- <p class="text-xs-center">{{election.description}}</p>

+     <p class="text-xs-center">{{election.description}}</p>

  

- <p class="text-xs-center"><a href="{{election.url}}">[More Information]</a></p>

+     <p class="text-xs-center"><a href="{{election.url}}">[More Information]</a></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) }}

-     {% endfor %}

+     <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) }}

+         {% endfor %}

  

-   {% if g.fas_user %}

-     <p>

-     {% if nextaction == 'vote' %}

-       <input type="hidden" name="action" value="submit" />

-       <input class="btn btn-primary btn-block m-t-1" type="submit" name="{{nextaction}}" value="Submit your vote" />

-     {% else %}

-       <input type="hidden" name="action" value="preview" />

-       <input class="btn btn-info btn-block m-t-1" type="submit" name="{{nextaction}}" value="Preview your vote" />

-     {% endif %}

-     </p>

-     {{ form.csrf_token }}

-   {% endif %}

- </form>

- </div>

+       {% if g.fas_user %}

+         <p>

+         {% if nextaction == 'vote' %}

+           <input type="hidden" name="action" value="submit" />

+           <input class="btn btn-primary btn-block m-t-1" type="submit" name="{{nextaction}}" value="Submit your vote" />

+         {% else %}

+           <input type="hidden" name="action" value="preview" />

+           <input class="btn btn-info btn-block m-t-1" type="submit" name="{{nextaction}}" value="Preview your vote" />

+         {% endif %}

+         </p>

+         {{ form.csrf_token }}

+       {% endif %}

+     </form>

+   </div>

  </div>

+ 

  <!-- Make this conditional on whether the user is logged in and can vote in the election -->

  {% if election.legal_voters.count() != 0 %}

    <p>
@@ -41,8 +48,6 @@ 

        <li>{{group.group_name}}</li>

      {% endfor %}

    </ul>

- {% else %}

-   <p />

  {% endif %}

  

  {% if election.voting_type == 'range' %}

@@ -2,51 +2,59 @@ 

  

  {% extends "base.html" %}

  {% block body %}

- <div class="col-md-6 col-md-offset-3 voting-sheet">

- <h1 class="text-xs-center"><strong>{{election.shortdesc}}</strong></h1>

  

- <p class="text-xs-center">{{election.description}}</p>

+ {% if nextaction == 'vote' %}

+ {% include "_claim_badge_page.html" %}

+ {% endif %}

  

- <p class="text-xs-center"><a href="{{election.url}}">[More Information]</a></p>

+ <div class="row">

+   <div class="col-md-6 col-md-offset-3 voting-sheet">

+     <h1 class="text-xs-center"><strong>{{election.shortdesc}}</strong></h1>

  

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

-     <div class="list-group">

-     {% for field in form if field.widget.input_type != 'hidden' %}

-       {% if field.type == "BooleanField" %}

-       <div class="list-group-item">

-         {{field}}

-         {{field.label}}

-       </div>

-       {% elif election.voting_type == "irc"%}

-         <div class="list-group-item">

-             {{ field.label }}

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

-         </div>

-       {% else %}

-         {% for subfield in field %}

+     <p class="text-xs-center">{{election.description}}</p>

+ 

+     <p class="text-xs-center"><a href="{{election.url}}">[More Information]</a></p>

+ 

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

+       <div class="list-group">

+         {% for field in form if field.widget.input_type != 'hidden' %}

+           {% if field.type == "BooleanField" %}

            <div class="list-group-item">

-               {{ subfield }}

-               {{ subfield.label }}

+             {{field}}

+             {{field.label}}

            </div>

+           {% elif election.voting_type == "irc"%}

+             <div class="list-group-item">

+                 {{ field.label }}

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

+             </div>

+           {% else %}

+             {% for subfield in field %}

+               <div class="list-group-item">

+                 {{ subfield }}

+                 {{ subfield.label }}

+               </div>

+             {% endfor %}

+           {% endif %}

          {% endfor %}

-       {% endif %}

-     {% endfor %}

-   </div>

+       </div>

  

-   {% if g.fas_user %}

-     <p>

-       {% if nextaction == 'vote' %}

-         <input type="hidden" name="action" value="submit" />

-         <input class="btn btn-primary btn-block m-t-1" type="submit" name="{{nextaction}}" value="Submit your vote" />

-       {% else %}

-         <input type="hidden" name="action" value="preview" />

-         <input class="btn btn-info btn-block m-t-1" type="submit" name="{{nextaction}}" value="Preview your vote" />

+       {% if g.fas_user %}

+         <p>

+           {% if nextaction == 'vote' %}

+             <input type="hidden" name="action" value="submit" />

+             <input class="btn btn-primary btn-block m-t-1" type="submit" name="{{nextaction}}" value="Submit your vote" />

+           {% else %}

+             <input type="hidden" name="action" value="preview" />

+             <input class="btn btn-info btn-block m-t-1" type="submit" name="{{nextaction}}" value="Preview your vote" />

+           {% endif %}

+         </p>

+         {{ form.csrf_token }}

        {% endif %}

-     </p>

-     {{ form.csrf_token }}

-   {% endif %}

- </form>

- </div>

+     </form>

+   </div>

+   </div>

  <!-- Make this conditional on whether the user is logged in and can vote in the election -->

  {% if election.legal_voters.count() != 0 %}

    <p>
@@ -57,7 +65,5 @@ 

        <li>{{group.group_name}}</li>

      {% endfor %}

    </ul>

- {% else %}

-   <p />

  {% endif %}

  {% endblock %}

file modified
+2 -1
@@ -15,7 +15,8 @@ 

  # the 'revision' command, regardless of autogenerate

  # revision_environment = false

  

- sqlalchemy.url = driver://user:pass@localhost/dbname

+ # We're using the one defined in the app's config

+ # sqlalchemy.url = driver://user:pass@localhost/dbname

  

  

  # Logging configuration