diff --git a/mo/web/org_round.py b/mo/web/org_round.py index a211d6ad01698d6d7c011e31809ca945f2bb0014..19e4f1e6d6ddb8b8c5ffed772a93847e8d9d854c 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 ddddc7df8f2f622a83a951de62106679b7c53834..bd91f5a844a660e1917ff0ee02e7c3be2ccdf16e 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 %}