From 5e5a50814ea77f76493be86324469108175ead72 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 25 2019 14:15:43 +0000 Subject: [PATCH 1/7] Fix the field name in the alembic migration We renamed the field from voted_badge to url_badge and it looks like we forgot to rename the field in the code itself. This commit fixes that. Signed-off-by: Pierre-Yves Chibon --- diff --git a/alembic/versions/5ecdd55b4af4_add_badge_support_to_elections.py b/alembic/versions/5ecdd55b4af4_add_badge_support_to_elections.py index 14ee9c8..e1e0b2e 100644 --- a/alembic/versions/5ecdd55b4af4_add_badge_support_to_elections.py +++ b/alembic/versions/5ecdd55b4af4_add_badge_support_to_elections.py @@ -18,7 +18,7 @@ def upgrade(): """ 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) ) From b86ceb415751849d0ca38e19a0c8b34499587dde Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 25 2019 14:16:37 +0000 Subject: [PATCH 2/7] Small indentation and UI fixes The indentation was not clear so we fixed it and we added a
on the vote_simple.html template for the two sections appear one above the other rather than next to each other. Signed-off-by: Pierre-Yves Chibon --- diff --git a/fedora_elections/templates/vote_range.html b/fedora_elections/templates/vote_range.html index 76c2a1d..2a6e857 100644 --- a/fedora_elections/templates/vote_range.html +++ b/fedora_elections/templates/vote_range.html @@ -3,34 +3,35 @@ {% extends "base.html" %} {% block body %}
-
-

{{election.shortdesc}}

+
+

{{election.shortdesc}}

-

{{election.description}}

+

{{election.description}}

-

[More Information]

+

[More Information]

-
- {% for field in form if field.widget.input_type != 'hidden' %} - {{ render_field_data_in_row( - field, usernamemap=usernamemap) }} - {% endfor %} + + {% for field in form if field.widget.input_type != 'hidden' %} + {{ render_field_data_in_row( + field, usernamemap=usernamemap) }} + {% endfor %} - {% if g.fas_user %} -

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

- {{ form.csrf_token }} - {% endif %} -
-
+ {% if g.fas_user %} +

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

+ {{ form.csrf_token }} + {% endif %} + +
+ {% if election.legal_voters.count() != 0 %}

@@ -41,8 +42,6 @@

  • {{group.group_name}}
  • {% endfor %} -{% else %} -

    {% endif %} {% if election.voting_type == 'range' %} diff --git a/fedora_elections/templates/vote_simple.html b/fedora_elections/templates/vote_simple.html index 2ad9e3c..76df9c1 100644 --- a/fedora_elections/templates/vote_simple.html +++ b/fedora_elections/templates/vote_simple.html @@ -2,51 +2,53 @@ {% extends "base.html" %} {% block body %} -

    -

    {{election.shortdesc}}

    +
    +
    +

    {{election.shortdesc}}

    -

    {{election.description}}

    +

    {{election.description}}

    -

    [More Information]

    +

    [More Information]

    -
    -
    - {% for field in form if field.widget.input_type != 'hidden' %} - {% if field.type == "BooleanField" %} -
    - {{field}} - {{field.label}} -
    - {% elif election.voting_type == "irc"%} -
    - {{ field.label }} - {{ field(class_="c-select pull-xs-right") }} -
    - {% else %} - {% for subfield in field %} + +
    + {% for field in form if field.widget.input_type != 'hidden' %} + {% if field.type == "BooleanField" %}
    - {{ subfield }} - {{ subfield.label }} + {{field}} + {{field.label}}
    + {% elif election.voting_type == "irc"%} +
    + {{ field.label }} + {{ field(class_="c-select pull-xs-right") }} +
    + {% else %} + {% for subfield in field %} +
    + {{ subfield }} + {{ subfield.label }} +
    + {% endfor %} + {% endif %} {% endfor %} - {% endif %} - {% endfor %} -
    +
    - {% if g.fas_user %} -

    - {% if nextaction == 'vote' %} - - - {% else %} - - + {% if g.fas_user %} +

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

    + {{ form.csrf_token }} {% endif %} -

    - {{ form.csrf_token }} - {% endif %} -
    -
    + +
    +
    {% if election.legal_voters.count() != 0 %}

    @@ -57,7 +59,5 @@

  • {{group.group_name}}
  • {% endfor %} -{% else %} -

    {% endif %} {% endblock %} From 4f9c1d34d101f9f304889e571dab91cab6c5526b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 25 2019 14:18:03 +0000 Subject: [PATCH 3/7] Use the database URL in used in the election app if specified Basically, instead of relying on the database url present in alembic.ini we use the one configured for the entire application. If one is specified in the alembic.ini though, it will be respected and used. Signed-off-by: Pierre-Yves Chibon --- diff --git a/alembic/env.py b/alembic/env.py index a280347..95f4087 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -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 @@ config = context.config # 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 @@ def run_migrations_offline(): 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 @@ def run_migrations_online(): 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(): diff --git a/files/alembic.ini b/files/alembic.ini index 920f5df..572c207 100644 --- a/files/alembic.ini +++ b/files/alembic.ini @@ -15,7 +15,8 @@ script_location = alembic # 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 From e8c3ea6e3fbf9f87efc203b3d332365db07f584d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 25 2019 14:19:30 +0000 Subject: [PATCH 4/7] Remove code that is no longer used With the port to OIDC, this code was basically not doing anything anymore so we can just drop it. Signed-off-by: Pierre-Yves Chibon --- diff --git a/fedora_elections/__init__.py b/fedora_elections/__init__.py index 06bed68..81e4b36 100644 --- a/fedora_elections/__init__.py +++ b/fedora_elections/__init__.py @@ -330,14 +330,7 @@ def auth_login(): 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') From 95ec4c42a7a4956e4b4f30a235e48a4184a083b3 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 25 2019 14:33:15 +0000 Subject: [PATCH 5/7] Offer to voters the possibility to claim their badge before voting The link appears on the page where they can review their vote, so before they actually vote. It will also appear once they have voted in the notification at the top. Signed-off-by: Pierre-Yves Chibon --- diff --git a/fedora_elections/templates/_claim_badge_page.html b/fedora_elections/templates/_claim_badge_page.html new file mode 100644 index 0000000..c91733c --- /dev/null +++ b/fedora_elections/templates/_claim_badge_page.html @@ -0,0 +1,10 @@ +{% if election.url_badge %} +

    + + + Do not forget to claim your badge! + +
    +{% endif %} diff --git a/fedora_elections/templates/vote_range.html b/fedora_elections/templates/vote_range.html index 2a6e857..b2b3a17 100644 --- a/fedora_elections/templates/vote_range.html +++ b/fedora_elections/templates/vote_range.html @@ -2,6 +2,11 @@ {% extends "base.html" %} {% block body %} + +{% if nextaction == 'vote' %} +{% include "_claim_badge_page.html" %} +{% endif %} +

    {{election.shortdesc}}

    diff --git a/fedora_elections/templates/vote_simple.html b/fedora_elections/templates/vote_simple.html index 76df9c1..2252678 100644 --- a/fedora_elections/templates/vote_simple.html +++ b/fedora_elections/templates/vote_simple.html @@ -2,6 +2,11 @@ {% extends "base.html" %} {% block body %} + +{% if nextaction == 'vote' %} +{% include "_claim_badge_page.html" %} +{% endif %} +

    {{election.shortdesc}}

    From 62e50a80be77a114baf9aa172ead44e390ec60de Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 25 2019 14:35:51 +0000 Subject: [PATCH 6/7] Replace github by pagure.io in the footer Fixes https://pagure.io/elections/issue/57 Signed-off-by: Pierre-Yves Chibon --- diff --git a/fedora_elections/templates/base.html b/fedora_elections/templates/base.html index 7672536..c128ae8 100644 --- a/fedora_elections/templates/base.html +++ b/fedora_elections/templates/base.html @@ -111,7 +111,7 @@

    Copyright © 2013-2016 Red Hat

    -

    Powered by the Powered by the elections app -- version {{ version }}

    From 2c1525ac4d9a5d5ff925401e173116097f6c8b37 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 25 2019 14:50:47 +0000 Subject: [PATCH 7/7] Specify the number of seats open on the page where voting happens Fixes https://pagure.io/elections/issue/53 Signed-off-by: Pierre-Yves Chibon --- diff --git a/fedora_elections/templates/vote_range.html b/fedora_elections/templates/vote_range.html index b2b3a17..d6f0f2b 100644 --- a/fedora_elections/templates/vote_range.html +++ b/fedora_elections/templates/vote_range.html @@ -15,6 +15,7 @@

    [More Information]

    +

    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( diff --git a/fedora_elections/templates/vote_simple.html b/fedora_elections/templates/vote_simple.html index 2252678..a088925 100644 --- a/fedora_elections/templates/vote_simple.html +++ b/fedora_elections/templates/vote_simple.html @@ -15,6 +15,7 @@

    [More Information]

    +

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

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