diff --git a/mo/web/org_contest.py b/mo/web/org_contest.py index 456c0b0565f7bb00a1964f35835ec5e965c698fc..ab5cacfda2d750a629b744088fc8de3695955d24 100644 --- a/mo/web/org_contest.py +++ b/mo/web/org_contest.py @@ -49,9 +49,9 @@ class ImportForm(FlaskForm): class ParticipantsFilterForm(PagerForm): - school = wtforms.StringField("Škola") - participation_place = wtforms.StringField("Soutěžní místo", render_kw={'autofocus': True}) - contest_place = wtforms.StringField("Soutěžní oblast", render_kw={'autofocus': True}) + school = mo_fields.School() + participation_place = mo_fields.Place("Soutěžní místo", render_kw={'autofocus': True}) + contest_place = mo_fields.Place("Soutěžní oblast", render_kw={'autofocus': True}) participation_state = wtforms.SelectField('Stav účasti', choices=[('*', '*')] + list(db.PartState.choices()), default='*') # format = wtforms.RadioField(choices=[('', 'Zobrazit'), ('csv', 'Stáhnout vše v CSV'), ('tsv', 'Stáhnout vše v TSV')]) @@ -66,24 +66,17 @@ class ParticipantsFilterForm(PagerForm): f_contest_place: Optional[db.Place] = None f_participation_state: Optional[db.PartState] = None - def validate(self): - if self.school.data: - self.f_school = db.get_place_by_code(self.school.data) - if not self.f_school: - flash(f"Zadaná škola '{self.school.data}' neexistuje", "danger") - self.f_school = db.School() - if self.participation_place.data: - self.f_participation_place = db.get_place_by_code(self.participation_place.data) - if not self.f_participation_place: - flash(f"Zadané soutěžní místo '{self.participation_place.data}' neexistuje", "danger") - self.f_participation_place = db.Place() - if self.contest_place.data: - self.f_contest_place = db.get_place_by_code(self.contest_place.data) - if not self.f_contest_place: - flash(f"Zadaná soutěžní oblast '{self.contest_place.data}' neexistuje", "danger") - self.f_contest_place = db.Place() - - self.f_participation_state = None if self.participation_state.data == '*' else self.participation_state.data + def validate_school(self, field): + self.f_school = field.place + + def validate_participation_place(self, field): + self.f_participation_place = field.place + + def validate_contest_place(self, field): + self.f_contest_place = field.place + + def validate_participation_state(self, field): + self.f_participation_state = None if field.data == '*' else field.data class ParticipantsActionForm(FlaskForm): @@ -452,8 +445,9 @@ def org_contest_list(id: int, site_id: Optional[int] = None): can_edit = rr.have_right(Right.manage_contest) and request.endpoint != 'org_contest_list_emails' format = request.args.get('format', "") - filter = ParticipantsFilterForm(request.args) - filter.validate() + filter = ParticipantsFilterForm(formdata=request.args) + if request.args: + filter.validate() query = get_contestants_query( round=master_contest.round, contest=master_contest, site=site, school=filter.f_school, diff --git a/mo/web/org_round.py b/mo/web/org_round.py index 19e4f1e6d6ddb8b8c5ffed772a93847e8d9d854c..94e4aaca170e1d6e50148a41cd6cf6b871dabc87 100644 --- a/mo/web/org_round.py +++ b/mo/web/org_round.py @@ -369,7 +369,7 @@ def org_round_list(id: int): can_edit = rr.have_right(Right.manage_round) and request.endpoint != 'org_round_list_emails' format = request.args.get('format', "") - filter = ParticipantsFilterForm(request.args) + filter = ParticipantsFilterForm(formdata=request.args) filter.validate() query = get_contestants_query( round=master_round, diff --git a/mo/web/templates/org_contest_list.html b/mo/web/templates/org_contest_list.html index edf82b924aaa910cd9f4b80ab458663ede048fac..e8b01899f8b27ce3ed879e8259d7adde140be7a7 100644 --- a/mo/web/templates/org_contest_list.html +++ b/mo/web/templates/org_contest_list.html @@ -16,9 +16,9 @@ Seznam účastníků {% if site %}v soutěžním místě {{ site.name }}{% else <form action="" method="GET" class="form form-inline" role="form"> <div class="form-row"> {% if not site %} - {{ wtf.form_field(filter.participation_place, placeholder='Kód', size=8) }} + {{ wtf.form_field(filter.participation_place, size=8) }} {% endif %} - {{ wtf.form_field(filter.school, placeholder='Kód', size=8) }} + {{ wtf.form_field(filter.school, size=8) }} {{ wtf.form_field(filter.participation_state) }} <div class="btn-group"> {{ wtf.form_field(filter.submit, class='btn btn-primary') }} diff --git a/mo/web/templates/org_round_list.html b/mo/web/templates/org_round_list.html index 343977ac7641cca560cc5ac6ad34d4c52cce6ccf..4dbdcf32b3daec2c0ded2ae58d7a419bae2b4da3 100644 --- a/mo/web/templates/org_round_list.html +++ b/mo/web/templates/org_round_list.html @@ -11,9 +11,9 @@ <div class="form-frame"> <form action="" method="GET" class="form form-inline" role="form"> <div class="form-row"> - {{ wtf.form_field(filter.contest_place, placeholder='Kód', size=8) }} - {{ wtf.form_field(filter.participation_place, placeholder='Kód', size=8) }} - {{ wtf.form_field(filter.school, placeholder='Kód', size=8) }} + {{ wtf.form_field(filter.contest_place, size=8) }} + {{ wtf.form_field(filter.participation_place, size=8) }} + {{ wtf.form_field(filter.school, size=8) }} {{ wtf.form_field(filter.participation_state) }} </div> <div class="form-row" style="margin-top: 5px;">