From 3d093f94e04e02b0374d6bd90df75cf15d6896c2 Mon Sep 17 00:00:00 2001 From: Ben Cotton Date: Mar 25 2019 13:54:15 +0000 Subject: [PATCH 1/3] Add support for requesting an 'I Voted' badge. Badges will be created to be requestable by URL. This URL will be provided by the admin. If set, the link will be given to the user after the ballot is submitted (or re-submitted). --- diff --git a/fedora_elections/admin.py b/fedora_elections/admin.py index c84417f..a1aafd4 100644 --- a/fedora_elections/admin.py +++ b/fedora_elections/admin.py @@ -74,6 +74,7 @@ def admin_new_election(): end_date=form.end_date.data, seats_elected=form.seats_elected.data, embargoed=int(form.embargoed.data), + voted_badge=form.voted_badge.data, voting_type=form.voting_type.data, max_votes=form.max_votes.data, candidates_are_fasusers=int(form.candidates_are_fasusers.data), diff --git a/fedora_elections/elections.py b/fedora_elections/elections.py index 4b515e2..24be36c 100644 --- a/fedora_elections/elections.py +++ b/fedora_elections/elections.py @@ -173,7 +173,7 @@ def vote_range(election, revote): and candidate.short_name not in ['csrf_token', 'action'] ] process_vote(candidates, election, votes, revote) - flask.flash("Your vote has been recorded. Thank you!") + say_thank_you(election) return safe_redirect_back() if form.action.data == 'preview': @@ -229,7 +229,7 @@ def vote_select(election, revote): and candidate.short_name not in ['csrf_token', 'action'] ] process_vote(candidates, election, votes, revote, cand_name) - flask.flash("Your vote has been recorded. Thank you!") + say_thank_you(election) return safe_redirect_back() if form.action.data == 'preview': @@ -269,7 +269,7 @@ def vote_simple(election, revote): and candidate.short_name not in ['csrf_token', 'action'] ] process_vote(candidates, election, votes, revote, value=1) - flask.flash("Your vote has been recorded. Thank you!") + say_thank_you(election) return safe_redirect_back() if form.action.data == 'preview': @@ -307,7 +307,7 @@ def vote_irc(election, revote): and candidate.short_name not in ['csrf_token', 'action'] ] process_vote(candidates, election, votes, revote, cand_name) - flask.flash("Your vote has been recorded. Thank you!") + say_thank_you(election) return safe_redirect_back() if form.action.data == 'preview': @@ -350,3 +350,11 @@ def process_vote( ) SESSION.add(new_vote) SESSION.commit() + + +def say_thank_you(election): + thank_you = "Your vote has been recorded. Thank you!" + if election.voted_badge: + thank_you = thank_you + '
Claim your I Voted badge.' + flask.flash(thank_you) diff --git a/fedora_elections/forms.py b/fedora_elections/forms.py index 322ed4d..54d2e0c 100644 --- a/fedora_elections/forms.py +++ b/fedora_elections/forms.py @@ -74,6 +74,12 @@ class ElectionForm(FlaskForm): embargoed = wtforms.BooleanField('Embargo results?', default=True) + voted_badge = wtforms.TextField( + 'Badge URL (optional)', [ + wtforms.validators.Optional(), + wtforms.validators.URL(), + wtforms.validators.Length(max=250)]) + lgl_voters = wtforms.TextField( 'Legal voters groups', [wtforms.validators.optional()]) diff --git a/fedora_elections/models.py b/fedora_elections/models.py index 1772d4d..b91a252 100644 --- a/fedora_elections/models.py +++ b/fedora_elections/models.py @@ -86,6 +86,7 @@ class Election(BASE): seats_elected = sa.Column(sa.Integer, nullable=False, default=1) embargoed = sa.Column(sa.Integer, nullable=False, default=0) voting_type = sa.Column(sa.Unicode(100), nullable=False, default=u'range') + voted_badge = sa.Column(sa.Unicode(250), nullable=False) max_votes = sa.Column(sa.Integer, nullable=True) candidates_are_fasusers = sa.Column( sa.Integer, nullable=False, default=0) diff --git a/fedora_elections/templates/_formhelpers.html b/fedora_elections/templates/_formhelpers.html index ba48487..f90bb94 100644 --- a/fedora_elections/templates/_formhelpers.html +++ b/fedora_elections/templates/_formhelpers.html @@ -112,6 +112,7 @@ {{ render_bootstrap_textfield_in_row(form.seats_elected) }} {{ render_bootstrap_checkbox_in_row(form.candidates_are_fasusers) }} {{ render_bootstrap_checkbox_in_row(form.embargoed) }} + {{ render_bootstrap_textfield_in_row(form.voted_badge) }} {{ render_bootstrap_textfield_in_row(form.lgl_voters, after="FAS groups allowed to vote on this election (CLA-done is always required)") }} {{ render_bootstrap_textfield_in_row(form.admin_grp, after="FAS groups allowed to view the result despite the embargo") }} From ea85cd17dc2161e932805bff3cbfd687a0e624b6 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 25 2019 13:55:43 +0000 Subject: [PATCH 2/3] Add an alembic migration script for the voted_badge field in elections 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 new file mode 100644 index 0000000..cdb7f84 --- /dev/null +++ b/alembic/versions/5ecdd55b4af4_add_badge_support_to_elections.py @@ -0,0 +1,27 @@ +"""Add badge support to elections + +Revision ID: 5ecdd55b4af4 +Revises: 2b8f5a6f10a4 +Create Date: 2019-03-18 12:21:59.536380 + +""" + +# revision identifiers, used by Alembic. +revision = '5ecdd55b4af4' +down_revision = '2b8f5a6f10a4' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + """ Add the voted_badge column to the Elections table. """ + op.add_column( + 'elections', + sa.Column('voted_badge', sa.Unicode(250), nullable=True) + ) + + +def downgrade(): + """ Drop the voted_badge column from the Elections table. """ + op.drop_column('elections', 'voted_badge') From e049a94b96502a218e15e8ca31d9a82e9f0cc09e Mon Sep 17 00:00:00 2001 From: Ben Cotton Date: Mar 25 2019 13:56:56 +0000 Subject: [PATCH 3/3] Update the field name and correct the nullability --- diff --git a/alembic/versions/5ecdd55b4af4_add_badge_support_to_elections.py b/alembic/versions/5ecdd55b4af4_add_badge_support_to_elections.py index cdb7f84..14ee9c8 100644 --- a/alembic/versions/5ecdd55b4af4_add_badge_support_to_elections.py +++ b/alembic/versions/5ecdd55b4af4_add_badge_support_to_elections.py @@ -15,7 +15,7 @@ import sqlalchemy as sa def upgrade(): - """ Add the voted_badge column to the Elections table. """ + """ Add the url_badge column to the Elections table. """ op.add_column( 'elections', sa.Column('voted_badge', sa.Unicode(250), nullable=True) @@ -23,5 +23,5 @@ def upgrade(): def downgrade(): - """ Drop the voted_badge column from the Elections table. """ - op.drop_column('elections', 'voted_badge') + """ Drop the url_badge column from the Elections table. """ + op.drop_column('elections', 'url_badge') diff --git a/fedora_elections/admin.py b/fedora_elections/admin.py index a1aafd4..c34694d 100644 --- a/fedora_elections/admin.py +++ b/fedora_elections/admin.py @@ -74,7 +74,7 @@ def admin_new_election(): end_date=form.end_date.data, seats_elected=form.seats_elected.data, embargoed=int(form.embargoed.data), - voted_badge=form.voted_badge.data, + url_badge=form.url_badge.data, voting_type=form.voting_type.data, max_votes=form.max_votes.data, candidates_are_fasusers=int(form.candidates_are_fasusers.data), diff --git a/fedora_elections/elections.py b/fedora_elections/elections.py index 24be36c..41a2804 100644 --- a/fedora_elections/elections.py +++ b/fedora_elections/elections.py @@ -354,7 +354,7 @@ def process_vote( def say_thank_you(election): thank_you = "Your vote has been recorded. Thank you!" - if election.voted_badge: + if election.url_badge: thank_you = thank_you + '
Claim your I Voted badge.' + election.url_badge + '" target=_new>Claim your I Voted badge.' flask.flash(thank_you) diff --git a/fedora_elections/forms.py b/fedora_elections/forms.py index 54d2e0c..1c3fb75 100644 --- a/fedora_elections/forms.py +++ b/fedora_elections/forms.py @@ -74,7 +74,7 @@ class ElectionForm(FlaskForm): embargoed = wtforms.BooleanField('Embargo results?', default=True) - voted_badge = wtforms.TextField( + url_badge = wtforms.TextField( 'Badge URL (optional)', [ wtforms.validators.Optional(), wtforms.validators.URL(), diff --git a/fedora_elections/models.py b/fedora_elections/models.py index b91a252..b82af00 100644 --- a/fedora_elections/models.py +++ b/fedora_elections/models.py @@ -86,7 +86,7 @@ class Election(BASE): seats_elected = sa.Column(sa.Integer, nullable=False, default=1) embargoed = sa.Column(sa.Integer, nullable=False, default=0) voting_type = sa.Column(sa.Unicode(100), nullable=False, default=u'range') - voted_badge = sa.Column(sa.Unicode(250), nullable=False) + url_badge = sa.Column(sa.Unicode(250), nullable=True) max_votes = sa.Column(sa.Integer, nullable=True) candidates_are_fasusers = sa.Column( sa.Integer, nullable=False, default=0) diff --git a/fedora_elections/templates/_formhelpers.html b/fedora_elections/templates/_formhelpers.html index f90bb94..0683977 100644 --- a/fedora_elections/templates/_formhelpers.html +++ b/fedora_elections/templates/_formhelpers.html @@ -112,7 +112,7 @@ {{ render_bootstrap_textfield_in_row(form.seats_elected) }} {{ render_bootstrap_checkbox_in_row(form.candidates_are_fasusers) }} {{ render_bootstrap_checkbox_in_row(form.embargoed) }} - {{ render_bootstrap_textfield_in_row(form.voted_badge) }} + {{ render_bootstrap_textfield_in_row(form.url_badge) }} {{ render_bootstrap_textfield_in_row(form.lgl_voters, after="FAS groups allowed to vote on this election (CLA-done is always required)") }} {{ render_bootstrap_textfield_in_row(form.admin_grp, after="FAS groups allowed to view the result despite the embargo") }}