From 8aaf7051eca28f57784f39fe533ff5b1903cf004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Setni=C4=8Dka?= <setnicka@seznam.cz> Date: Fri, 19 Feb 2021 01:45:16 +0100 Subject: [PATCH] =?UTF-8?q?Zakl=C3=A1d=C3=A1n=C3=AD=20=C5=99e=C5=A1en?= =?UTF-8?q?=C3=AD=20z=20tabulky=20v=C5=A1ech=20=C5=99e=C5=A1en=C3=AD=20sou?= =?UTF-8?q?t=C4=9B=C5=BEe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Část #108 --- mo/web/org_contest.py | 45 +++++++++++++++++++++ mo/web/templates/org_contest_solutions.html | 29 +++++++++++-- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/mo/web/org_contest.py b/mo/web/org_contest.py index 1d1e4482..cc276230 100644 --- a/mo/web/org_contest.py +++ b/mo/web/org_contest.py @@ -1030,12 +1030,22 @@ def org_contest_task(contest_id: int, task_id: int, site_id: Optional[int] = Non ) +class ContestSolutionsEditForm(FlaskForm): + submit = wtforms.SubmitField("Založit označená řešení") + + @app.route('/org/contest/c/<int:id>/solutions', methods=('GET', 'POST')) @app.route('/org/contest/c/<int:id>/site/<int:site_id>/solutions', methods=('GET', 'POST')) +@app.route('/org/contest/c/<int:id>/solutions/edit', methods=('GET', 'POST'), endpoint="org_contest_solutions_edit") +@app.route('/org/contest/c/<int:id>/site/<int:site_id>/solutions/edit', methods=('GET', 'POST'), endpoint="org_contest_solutions_edit") def org_contest_solutions(id: int, site_id: Optional[int] = None): sc = get_solution_context(id, None, None, site_id) sess = db.get_session() + edit_action = request.endpoint == "org_contest_solutions_edit" + if edit_action and not sc.allow_create_solutions: + raise werkzeug.exceptions.Forbidden() + pions_subq = sess.query(db.Participation.user_id).filter_by(contest=sc.contest) if sc.site: pions_subq = pions_subq.filter_by(place=sc.site) @@ -1078,11 +1088,46 @@ def org_contest_solutions(id: int, site_id: Optional[int] = None): for s in sols: task_sols[s.task_id][s.user_id] = s + edit_form: Optional[ContestSolutionsEditForm] = None + if edit_action: + edit_form = ContestSolutionsEditForm() + if edit_form.validate_on_submit(): + new_sol_count = 0 + for task in tasks: + for pion in pions: + if pion.user_id in task_sols[task.task_id]: + continue # již existuje + if not request.form.get(f"create_sol_{task.task_id}_{pion.user_id}"): + continue # nikdo nežádá o vytvoření + + sol = db.Solution(task=task, user=pion.user) + sess.add(sol) + mo.util.log( + type=db.LogType.participant, + what=pion.user_id, + details={ + 'action': 'solution-created', + 'task': task.task_id, + }, + ) + app.logger.info(f"Řešení úlohy {task.code} od účastníka {pion.user_id} založeno") + new_sol_count += 1 + + if new_sol_count > 0: + sess.commit() + flash(inflect_by_number(new_sol_count, "Založeno", "Založena", "Založeno") + ' ' + + inflect_number(new_sol_count, "nové řešení", "nová řešení", "nových řešení"), + "success") + else: + flash("Žádné změny k uložení", "info") + return redirect(url_for('org_contest_solutions', id=id, site_id=site_id)) + return render_template( 'org_contest_solutions.html', contest=sc.contest, site=sc.site, sc=sc, pions=pions, tasks=tasks, tasks_sols=task_sols, paper_counts=paper_counts, paper_link=lambda u, p: mo.web.util.org_paper_link(sc.contest, sc.site, u, p), + edit_form=edit_form, ) diff --git a/mo/web/templates/org_contest_solutions.html b/mo/web/templates/org_contest_solutions.html index 2017feb1..e59d31ab 100644 --- a/mo/web/templates/org_contest_solutions.html +++ b/mo/web/templates/org_contest_solutions.html @@ -4,10 +4,10 @@ {% set site_id = site.place_id if site else None %} {% block title %} -Tabulka řešení {% if site %}soutěžního místa {{ site.name }}{% else %}oblasti {{ contest.place.name }}{% endif %} +{{ "Založení řešení" if edit_form else "Tabulka řešení" }} {% if site %}soutěžního místa {{ site.name }}{% else %}oblasti {{ contest.place.name }}{% endif %} {% endblock %} {% block breadcrumbs %} -{{ contest_breadcrumbs(round=round, contest=contest, site=site, action="Tabulka řešení") }} +{{ contest_breadcrumbs(round=round, contest=contest, site=site, action="Založení řešení" if edit_form else "Tabulka řešení") }} {% endblock %} {% block body %} @@ -24,6 +24,10 @@ Tabulka řešení {% if site %}soutěžního místa {{ site.name }}{% else %}obl Odkazem v záhlaví se lze dostat na detailní výpis odevzdání všech uživatelů pro konkrétní úlohu. Symbol <span class="icon">🗐</span> značí, že existuje více verzí dostupných v detailu.</p> +{% if edit_form %} +<form class="form" method="POST"> +{{ edit_form.csrf_token }} +{% endif %} <table class="data full center"> <colgroup><col span="2"></colgroup> {% for task in tasks %} @@ -87,7 +91,13 @@ konkrétní úlohu. Symbol <span class="icon">🗐</span> značí, že existuje {% endif %} <td class="sol"> {% else %} - <td colspan=3>– + <td colspan=3> + {% if edit_form %} + <label> + <input type="checkbox" name="create_sol_{{task.task_id}}_{{u.user_id}}"> + Založit + </label> + {% else %}–{% endif %} <td> {% endif %} <a class="btn btn-xs btn-link icon" title="Detail řešení" href="{{ url_for('org_submit_list', contest_id=contest.contest_id, user_id=u.user_id, task_id=task.task_id, site_id=site_id) }}">🔍</a> @@ -108,5 +118,18 @@ konkrétní úlohu. Symbol <span class="icon">🗐</span> značí, že existuje <td> </tfoot> </table> +{% if edit_form %} + <div class='btn-group'> + {{ wtf.form_field(edit_form.submit, class="btn btn-primary") }} + <a class="btn btn-default" href="{{ url_for('org_contest_solutions', id=contest.contest_id, site_id=site_id) }}">Zrušit</a> + </div> +</form> +{% else %} +<div class='btn-group'> + {% if sc.allow_create_solutions %} + <a class="btn btn-primary" href="{{ url_for('org_contest_solutions_edit', id=contest.contest_id, site_id=site_id) }}">Založit řešení</a> + {% endif %} +</div> +{% endif %} {% endblock %} -- GitLab