Skip to content
Snippets Groups Projects
Commit 8aaf7051 authored by Jiří Setnička's avatar Jiří Setnička
Browse files

Zakládání řešení z tabulky všech řešení soutěže

Část #108
parent 3b45f5ee
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !30. Comments created here will be created in the context of that merge request.
...@@ -1030,12 +1030,22 @@ def org_contest_task(contest_id: int, task_id: int, site_id: Optional[int] = Non ...@@ -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>/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>/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): def org_contest_solutions(id: int, site_id: Optional[int] = None):
sc = get_solution_context(id, None, None, site_id) sc = get_solution_context(id, None, None, site_id)
sess = db.get_session() 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) pions_subq = sess.query(db.Participation.user_id).filter_by(contest=sc.contest)
if sc.site: if sc.site:
pions_subq = pions_subq.filter_by(place=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): ...@@ -1078,11 +1088,46 @@ def org_contest_solutions(id: int, site_id: Optional[int] = None):
for s in sols: for s in sols:
task_sols[s.task_id][s.user_id] = s 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( return render_template(
'org_contest_solutions.html', 'org_contest_solutions.html',
contest=sc.contest, site=sc.site, sc=sc, contest=sc.contest, site=sc.site, sc=sc,
pions=pions, tasks=tasks, tasks_sols=task_sols, paper_counts=paper_counts, 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), paper_link=lambda u, p: mo.web.util.org_paper_link(sc.contest, sc.site, u, p),
edit_form=edit_form,
) )
... ...
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
{% set site_id = site.place_id if site else None %} {% set site_id = site.place_id if site else None %}
{% block title %} {% 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 %} {% endblock %}
{% block breadcrumbs %} {% 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 %} {% endblock %}
{% block body %} {% block body %}
...@@ -24,6 +24,10 @@ Tabulka řešení {% if site %}soutěžního místa {{ site.name }}{% else %}obl ...@@ -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 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> 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"> <table class="data full center">
<colgroup><col span="2"></colgroup> <colgroup><col span="2"></colgroup>
{% for task in tasks %} {% for task in tasks %}
...@@ -87,7 +91,13 @@ konkrétní úlohu. Symbol <span class="icon">🗐</span> značí, že existuje ...@@ -87,7 +91,13 @@ konkrétní úlohu. Symbol <span class="icon">🗐</span> značí, že existuje
{% endif %} {% endif %}
<td class="sol"> <td class="sol">
{% else %} {% 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> <td>
{% endif %} {% 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> <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 ...@@ -108,5 +118,18 @@ konkrétní úlohu. Symbol <span class="icon">🗐</span> značí, že existuje
<td> <td>
</tfoot> </tfoot>
</table> </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 %} {% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment