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

Přidán formulář na editaci registrace do ročníku

Closes #96
parent a24c8602
No related branches found
No related tags found
1 merge request!89Přidán formulář na editaci registrace do ročníku
This commit is part of merge request !89. Comments created here will be created in the context of that merge request.
...@@ -485,3 +485,79 @@ def org_user_new(): ...@@ -485,3 +485,79 @@ def org_user_new():
if not is_duplicate_name: if not is_duplicate_name:
del form.allow_duplicate_name del form.allow_duplicate_name
return render_template('org_user_new.html', form=form, is_org=is_org) return render_template('org_user_new.html', form=form, is_org=is_org)
class SchoolField(wtforms.StringField):
def process_data(field, obj: int):
field.data = f"#{obj}"
def populate_obj(field, obj, name):
setattr(obj, name, int(field.data[1:]))
def pre_validate(field, form):
try:
mo.users.validate_and_find_school(field.data)
except mo.CheckError as e:
raise wtforms.ValidationError(str(e))
class ParticipantEditForm(FlaskForm):
school = SchoolField("Škola", validators=[Required()], render_kw={'autofocus': True})
grade = wtforms.StringField("Třída", validators=[Required()])
birth_year = wtforms.IntegerField("Rok narození", validators=[Required()])
submit = wtforms.SubmitField("Uložit")
def validate_grade(self, field):
school_place = None
try:
school_place = mo.users.validate_and_find_school(self.school.data)
except mo.CheckError:
pass
if school_place is not None:
try:
field.data = mo.users.normalize_grade(field.data, school_place.school)
except mo.CheckError as e:
raise wtforms.ValidationError(str(e))
def validate_birth_year(self, field):
r = field.data
if r < 2000 or r > 2099:
raise wtforms.ValidationError('Rok narození musí být v intervalu [2000,2099]')
@app.route('/org/user/<int:user_id>/participant/<int:year>/edit', methods=('GET', 'POST'))
def org_user_participant_edit(user_id: int, year: int):
sess = db.get_session()
user = mo.users.user_by_uid(user_id)
if not user:
raise werkzeug.exceptions.NotFound()
rr = g.gatekeeper.rights_generic()
if not rr.can_edit_user(user):
raise werkzeug.exceptions.Forbidden()
participant = sess.query(db.Participant).filter_by(user_id=user.user_id).filter_by(year=year).one_or_none()
if participant is None:
raise werkzeug.exceptions.NotFound()
form = ParticipantEditForm(obj=participant)
if form.validate_on_submit():
check = True
if check:
form.populate_obj(participant)
if sess.is_modified(participant):
changes = db.get_object_changes(participant)
app.logger.info(f"Participant id {id} year {year} modified, changes: {changes}")
mo.util.log(
type=db.LogType.participant,
what=user_id,
details={'action': 'edit_participant', 'year': year, 'changes': changes},
)
sess.commit()
flash('Změny registrace uloženy', 'success')
else:
flash('Žádné změny k uložení', 'info')
return redirect(url_for('org_user', id=user_id))
return render_template('org_user_participant_edit.html', user=user, year=year, form=form)
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
<table class="data full"> <table class="data full">
<thead> <thead>
<tr> <tr>
<th>Ročník<th>Škola<th>Třída<th>Rok narození <th>Ročník<th>Škola<th>Třída<th>Rok narození<th>Akce
</tr> </tr>
</thead> </thead>
{% for participant in participants %} {% for participant in participants %}
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
<td><a href="{{ url_for('org_place', id=participant.school) }}">{{ participant.school_place.name }}</a> <td><a href="{{ url_for('org_place', id=participant.school) }}">{{ participant.school_place.name }}</a>
<td>{{ participant.grade }} <td>{{ participant.grade }}
<td>{{ participant.birth_year }} <td>{{ participant.birth_year }}
<td><a class="btn btn-xs btn-primary" href="{{ url_for('org_user_participant_edit', user_id=user.user_id, year=participant.year) }}">Editovat</a>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
......
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block title %}Editace registrace soutěžícího {{ user.full_name() }} v {{ year }}. ročníku{% endblock %}
{% block body %}
{{ wtf.quick_form(form, form_type='horizontal', button_map={'submit': 'primary'}) }}
{% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment