From f9d98c05de329ed0e54d2eae8f689bc70a0907d4 Mon Sep 17 00:00:00 2001 From: Jiri Kalvoda <jirikalvoda@kam.mff.cuni.cz> Date: Sun, 1 Aug 2021 10:56:16 +0200 Subject: [PATCH] Fields: AddContestForm --- mo/web/org_round.py | 9 +++------ mo/web/templates/org_round.html | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/mo/web/org_round.py b/mo/web/org_round.py index a211d6ad..19e4f1e6 100644 --- a/mo/web/org_round.py +++ b/mo/web/org_round.py @@ -104,7 +104,7 @@ def delete_task(round_id: int, form: TaskDeleteForm) -> bool: class AddContestForm(FlaskForm): - place_code = wtforms.StringField('Nová soutěž v oblasti:', validators=[validators.Required()]) + place = mo_fields.Place('Nová soutěž v oblasti:', validators=[validators.Required()]) create_contest = wtforms.SubmitField('Založit') @@ -112,10 +112,7 @@ def add_contest(round: db.Round, form: AddContestForm) -> bool: if not (request.method == 'POST' and 'create_contest' in request.form and form.validate_on_submit()): return False - place = db.get_place_by_code(form.place_code.data) - if place is None: - flash(f'Místo s kódem {form.place_code.data} neexistuje', 'danger') - return False + place: db.Place = form.place.place if place.level != round.level: flash(f'{place.type_name().title()} {place.name} není {round.get_level().name}', 'danger') @@ -229,7 +226,7 @@ def org_round(id: int): return redirect(url_for('org_round', id=id)) form_add_contest = AddContestForm() - form_add_contest.place_code.label.text = "Nová soutěž " + round.get_level().in_name() + form_add_contest.place.label.text = "Nová soutěž " + round.get_level().in_name() if add_contest(round, form_add_contest): return redirect(url_for('org_round', id=id)) diff --git a/mo/web/templates/org_round.html b/mo/web/templates/org_round.html index ddddc7df..bd91f5a8 100644 --- a/mo/web/templates/org_round.html +++ b/mo/web/templates/org_round.html @@ -122,7 +122,7 @@ {% if can_add_contest %} <form action="" method="POST" class="form-inline"> {{ form_add_contest.csrf_token() }} - {{ wtf.form_field(form_add_contest.place_code) }} + {{ wtf.form_field(form_add_contest.place) }} {{ wtf.form_field(form_add_contest.create_contest) }} </form> {% endif %} -- GitLab