Skip to content

Commit

Permalink
voting identifier templates for proposition types
Browse files Browse the repository at this point in the history
  • Loading branch information
Holger Burbach committed Feb 10, 2021
1 parent 6b49a36 commit 6b5967a
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""voting_identifier_template for propositiontypes
Revision ID: cbe0faa6a28a
Revises: e2ce064655e8
Create Date: 2021-02-10 15:56:33.797513
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'cbe0faa6a28a'
down_revision = 'e2ce064655e8'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('voting_id_counter',
sa.Column('proposition_type_id', sa.Integer(), nullable=False),
sa.Column('voting_phase_id', sa.Integer(), nullable=False),
sa.Column('counter', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['proposition_type_id'], ['propositiontypes.id'], name=op.f('fk_voting_id_counter_proposition_type_id_propositiontypes')),
sa.ForeignKeyConstraint(['voting_phase_id'], ['votingphases.id'], name=op.f('fk_voting_id_counter_voting_phase_id_votingphases')),
sa.PrimaryKeyConstraint('proposition_type_id', 'voting_phase_id', name=op.f('pk_voting_id_counter'))
)
op.drop_table('voting_module')
op.drop_table('votingresults')
op.add_column('propositiontypes', sa.Column('voting_identifier_template', sa.Text(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('propositiontypes', 'voting_identifier_template')
op.create_table('votingresults',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('data', sa.TEXT(), autoincrement=False, nullable=True),
sa.Column('ballot_id', sa.INTEGER(), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name='votingresults_pkey')
)
op.create_table('voting_module',
sa.Column('id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('name', sa.TEXT(), autoincrement=False, nullable=False),
sa.Column('description', sa.TEXT(), autoincrement=False, nullable=True),
sa.Column('base_url', sa.TEXT(), autoincrement=False, nullable=False),
sa.Column('module_type', sa.TEXT(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name='pk_voting_module'),
sa.UniqueConstraint('name', name='uq_voting_module_name')
)
op.drop_table('voting_id_counter')
# ### end Alembic commands ###
15 changes: 14 additions & 1 deletion src/ekklesia_portal/concepts/ballot/ballot_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from webob.exc import HTTPBadRequest

from ekklesia_portal.app import App
from ekklesia_portal.datamodel import Ballot, SubjectArea, VotingPhase
from ekklesia_portal.datamodel import Ballot, SubjectArea, VotingPhase, VotingIdCounter
from ekklesia_portal.permission import EditPermission

from .ballot_cells import BallotCell, BallotsCell, EditBallotCell
Expand Down Expand Up @@ -67,5 +67,18 @@ def update(self, request, appstruct):
if not department_allowed:
return HTTPBadRequest()

for proposition in self.propositions:
if not proposition.voting_identifier and self.proposition_type.voting_identifier_template:
v_id_cnt = request.q(VotingIdCounter).filter(VotingIdCounter.proposition_type_id == self.proposition_type_id, VotingIdCounter.voting_phase_id == self.voting_id).scalar()
if v_id_cnt is None:
v_id_cnt = VotingIdCounter(proposition_type_id = self.proposition_type_id, voting_phase_id = self.voting_id, counter= 0)
request.db_session.add(v_id_cnt)
v_id_cnt.counter += 1
try:
proposition.voting_identifier= self.proposition_type.voting_identifier_template.format(v_id_cnt.counter)
except Exception as e:
print("\nproposition type {0}: invalid voting identifier template {1}\n".format(self.proposition_type.name, self.proposition_type.voting_identifier_template))
return HTTPBadRequest()

self.update(**appstruct)
return redirect(request.link(self))
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class PropositionTypeSchema(Schema):
name = string_property(title=_('name'), validator=Length(max=64))
abbreviation = string_property(title=_('abbreviation'), validator=Length(max=3))
voting_identifier_template = string_property(title=_('voting_identifier_template'), validator=Length(min=0, max=30), missing=None)
description = string_property(title=_('description'), validator=Length(min=10, max=4000), missing='')
policy_id = int_property(title=_('policy'))

Expand Down
8 changes: 8 additions & 0 deletions src/ekklesia_portal/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ class PropositionType(Base): # Antragsart
id: int = C(Integer, Sequence('id_seq', optional=True), primary_key=True)
name: str = C(Text, unique=True, nullable=False)
abbreviation: str = C(Text, unique=True, nullable=False)
voting_identifier_template: str = C(Text, nullable=True)
description: str = C(Text, server_default='')
policy_id: int = C(Integer, ForeignKey('policies.id'), nullable=False)
policy: Policy = relationship("Policy", back_populates="proposition_types")
Expand Down Expand Up @@ -323,6 +324,13 @@ class VotingPhaseType(Base):
voting_type = C(Enum(VotingType), nullable=False) # online, urn, assembly, board


class VotingIdCounter(Base):
__tablename__ = 'voting_id_counter'
proposition_type_id: int = C(Integer, ForeignKey('propositiontypes.id'), primary_key=True)
voting_phase_id: int = C(Integer, ForeignKey('votingphases.id'), primary_key=True)
counter: int = C(Integer, nullable=True)


class VotingPhase(Base): # Abstimmungsperiode
__tablename__ = 'votingphases'
__table_args__ = (
Expand Down
3 changes: 3 additions & 0 deletions src/ekklesia_portal/translations/de/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,9 @@ msgstr "Nein"
msgid "vote_by_user_abstention"
msgstr "Enthaltung"

msgid "voting_identifier_template"
msgstr "Muster für Bezeichner"

#~ msgid "translation"
#~ msgstr "Übersetzung"

Expand Down
4 changes: 4 additions & 0 deletions src/ekklesia_portal/translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,10 @@ msgstr "No"
msgid "vote_by_user_abstention"
msgstr "Abstention"

msgid "voting_identifier_template"
msgstr "Template For Identifier"


#~ msgid "follow"
#~ msgstr "Follow"

Expand Down

0 comments on commit 6b5967a

Please sign in to comment.