Skip to content
Snippets Groups Projects
Commit f9d98c05 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

Fields: AddContestForm

parent cc06abe8
Branches
No related tags found
1 merge request!92Používání mo.web.fields
This commit is part of merge request !92. Comments created here will be created in the context of that merge request.
...@@ -104,7 +104,7 @@ def delete_task(round_id: int, form: TaskDeleteForm) -> bool: ...@@ -104,7 +104,7 @@ def delete_task(round_id: int, form: TaskDeleteForm) -> bool:
class AddContestForm(FlaskForm): 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') create_contest = wtforms.SubmitField('Založit')
...@@ -112,10 +112,7 @@ def add_contest(round: db.Round, form: AddContestForm) -> bool: ...@@ -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()): if not (request.method == 'POST' and 'create_contest' in request.form and form.validate_on_submit()):
return False return False
place = db.get_place_by_code(form.place_code.data) place: db.Place = form.place.place
if place is None:
flash(f'Místo s kódem {form.place_code.data} neexistuje', 'danger')
return False
if place.level != round.level: if place.level != round.level:
flash(f'{place.type_name().title()} {place.name} není {round.get_level().name}', 'danger') flash(f'{place.type_name().title()} {place.name} není {round.get_level().name}', 'danger')
...@@ -229,7 +226,7 @@ def org_round(id: int): ...@@ -229,7 +226,7 @@ def org_round(id: int):
return redirect(url_for('org_round', id=id)) return redirect(url_for('org_round', id=id))
form_add_contest = AddContestForm() 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): if add_contest(round, form_add_contest):
return redirect(url_for('org_round', id=id)) return redirect(url_for('org_round', id=id))
......
...@@ -122,7 +122,7 @@ ...@@ -122,7 +122,7 @@
{% if can_add_contest %} {% if can_add_contest %}
<form action="" method="POST" class="form-inline"> <form action="" method="POST" class="form-inline">
{{ form_add_contest.csrf_token() }} {{ 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) }} {{ wtf.form_field(form_add_contest.create_contest) }}
</form> </form>
{% endif %} {% endif %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment