Source code for election_day.forms.upload.election
from __future__ import annotations
from onegov.election_day import _
from onegov.election_day.forms.upload.common import ALLOWED_MIME_TYPES
from onegov.election_day.forms.upload.common import MAX_FILE_SIZE
from onegov.form import Form
from onegov.form.fields import UploadField
from onegov.form.validators import FileSizeLimit
from wtforms.fields import RadioField
from wtforms.validators import DataRequired
from wtforms.validators import InputRequired
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from onegov.election_day.models import Canton
from onegov.election_day.models import Election
from onegov.election_day.models import Municipality
[docs]
class UploadElectionBaseForm(Form):
[docs]
file_format = RadioField(
_('File format'),
choices=[
('internal', 'OneGov Cloud'),
],
validators=[
InputRequired()
],
default='internal'
)
[docs]
results = UploadField(
label=_('Results'),
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
render_kw={'force_simple': True},
depends_on=('file_format', '!wabsti_c'),
)
[docs]
def adjust(
self,
principal: Canton | Municipality,
election: Election
) -> None:
""" Adjusts the form to the given principal and election. """
assert hasattr(election, 'data_sources')
if election.data_sources:
self.file_format.choices = [
('internal', 'OneGov Cloud'),
('wabsti_c', 'WabstiCExport')
]
[docs]
class UploadMajorzElectionForm(UploadElectionBaseForm):
[docs]
wm_gemeinden = UploadField(
label='WM_Gemeinden.csv',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
depends_on=('file_format', 'wabsti_c'),
render_kw={'force_simple': True}
)
[docs]
wm_kandidaten = UploadField(
label='WM_Kandidaten.csv',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
depends_on=('file_format', 'wabsti_c'),
render_kw={'force_simple': True}
)
[docs]
wm_kandidatengde = UploadField(
label='WM_KandidatenGde.csv',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
depends_on=('file_format', 'wabsti_c'),
render_kw={'force_simple': True}
)
[docs]
wm_wahl = UploadField(
label='WM_Wahl',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
depends_on=('file_format', 'wabsti_c'),
render_kw={'force_simple': True}
)
[docs]
wmstatic_gemeinden = UploadField(
label='WMStatic_Gemeinden.csv',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
depends_on=('file_format', 'wabsti_c'),
render_kw={'force_simple': True}
)
[docs]
class UploadProporzElectionForm(UploadElectionBaseForm):
[docs]
wp_gemeinden = UploadField(
label='WP_Gemeinden',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
render_kw={'force_simple': True},
depends_on=('file_format', 'wabsti_c')
)
[docs]
wp_kandidaten = UploadField(
label='WP_Kandidaten',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
render_kw={'force_simple': True},
depends_on=('file_format', 'wabsti_c')
)
[docs]
wp_kandidatengde = UploadField(
label='WP_KandidatenGde',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
render_kw={'force_simple': True},
depends_on=('file_format', 'wabsti_c')
)
[docs]
wp_listen = UploadField(
label='WP_Listen',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
render_kw={'force_simple': True},
depends_on=('file_format', 'wabsti_c')
)
[docs]
wp_listengde = UploadField(
label='WP_ListenGde',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
render_kw={'force_simple': True},
depends_on=('file_format', 'wabsti_c')
)
[docs]
wp_wahl = UploadField(
label='WP_Wahl',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
depends_on=('file_format', 'wabsti_c'),
render_kw={'force_simple': True}
)
[docs]
wpstatic_gemeinden = UploadField(
label='WPStatic_Gemeinden',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
render_kw={'force_simple': True},
depends_on=('file_format', 'wabsti_c')
)
[docs]
wpstatic_kandidaten = UploadField(
label='WPStatic_Kandidaten',
validators=[
DataRequired(),
FileSizeLimit(MAX_FILE_SIZE)
],
allowed_mimetypes=ALLOWED_MIME_TYPES,
render_kw={'force_simple': True},
depends_on=('file_format', 'wabsti_c')
)