diff --git a/mo/web/org_users.py b/mo/web/org_users.py index c29beed486be54a99e4d3b6c3ce72667168f608c..b2ceb96e431b63218b439dac66a61db908cb84eb 100644 --- a/mo/web/org_users.py +++ b/mo/web/org_users.py @@ -17,6 +17,7 @@ from mo.rights import Right import mo.util import mo.users from mo.web import app +import mo.web.fields as mo_fields from mo.web.util import PagerForm @@ -485,3 +486,47 @@ def org_user_new(): if not is_duplicate_name: del form.allow_duplicate_name return render_template('org_user_new.html', form=form, is_org=is_org) + + +class ParticipantEditForm(FlaskForm): + school = mo_fields.School("Škola", validators=[Required()], render_kw={'autofocus': True}) + grade = mo_fields.Grade("Třída", validators=[Required()]) + birth_year = mo_fields.BirthYear("Rok narození", validators=[Required()]) + submit = wtforms.SubmitField("Uložit") + + +@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(): + 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) diff --git a/mo/web/templates/org_user.html b/mo/web/templates/org_user.html index e76644b20ea3f1dd6eb8292f942428556b15c25b..966d4b94591f593b6f012aca424ba3a5ddaabc6b 100644 --- a/mo/web/templates/org_user.html +++ b/mo/web/templates/org_user.html @@ -43,7 +43,7 @@ <table class="data full"> <thead> <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> </thead> {% for participant in participants %} @@ -52,6 +52,7 @@ <td><a href="{{ url_for('org_place', id=participant.school) }}">{{ participant.school_place.name }}</a> <td>{{ participant.grade }} <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> {% endfor %} </table> diff --git a/mo/web/templates/org_user_participant_edit.html b/mo/web/templates/org_user_participant_edit.html new file mode 100644 index 0000000000000000000000000000000000000000..a4245de62fb650d49beda17948a7fc6f5af16c23 --- /dev/null +++ b/mo/web/templates/org_user_participant_edit.html @@ -0,0 +1,8 @@ +{% 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 %}