Skip to content
Snippets Groups Projects
Commit e4af16e2 authored by Martin Mareš's avatar Martin Mareš
Browse files

Merge branch 'master' of gitlab.kam.mff.cuni.cz:mj/mo-submit

parents b86dcdf8 7349e365
No related branches found
No related tags found
No related merge requests found
...@@ -188,6 +188,11 @@ class ParticipantsActionForm(FlaskForm): ...@@ -188,6 +188,11 @@ class ParticipantsActionForm(FlaskForm):
return True return True
class DownloadButtonForm(FlaskForm):
download = wtforms.SubmitField('Stáhnout všechna řešení jako ZIP')
download_feedback = wtforms.SubmitField('Stáhnout opravená jako ZIP')
def get_contest(id: int) -> db.Contest: def get_contest(id: int) -> db.Contest:
contest = (db.get_session().query(db.Contest) contest = (db.get_session().query(db.Contest)
.options(joinedload(db.Contest.place), .options(joinedload(db.Contest.place),
...@@ -687,6 +692,23 @@ def get_solutions_query( ...@@ -687,6 +692,23 @@ def get_solutions_query(
return query return query
def download_solutions(form: DownloadButtonForm, solutions: List[db.Solution], subject: str) -> bool:
if not form.validate_on_submit():
return False
if form.download.data:
paper_ids = [sol.final_submit for sol in solutions if sol.final_submit is not None]
mo.jobs.submit.schedule_download_submits(paper_ids, f'Odevzdaná řešení {subject}', g.user)
flash('Příprava odevzdaných řešení ke stažení zahájena.', 'success')
return True
if form.download_feedback.data:
paper_ids = [sol.final_feedback or sol.final_submit for sol in solutions if sol.final_submit is not None]
mo.jobs.submit.schedule_download_submits(paper_ids, f'Opravená řešení {subject}', g.user)
flash('Příprava opravených řešení ke stažení zahájena.', 'success')
return True
@app.route('/org/contest/c/<int:contest_id>/task/<int:task_id>/', methods=('GET', 'POST')) @app.route('/org/contest/c/<int:contest_id>/task/<int:task_id>/', methods=('GET', 'POST'))
@app.route('/org/contest/c/<int:contest_id>/site/<int:site_id>/task/<int:task_id>/', methods=('GET', 'POST')) @app.route('/org/contest/c/<int:contest_id>/site/<int:site_id>/task/<int:task_id>/', methods=('GET', 'POST'))
def org_contest_task_submits(contest_id: int, task_id: int, site_id: Optional[int] = None): def org_contest_task_submits(contest_id: int, task_id: int, site_id: Optional[int] = None):
...@@ -697,10 +719,8 @@ def org_contest_task_submits(contest_id: int, task_id: int, site_id: Optional[in ...@@ -697,10 +719,8 @@ def org_contest_task_submits(contest_id: int, task_id: int, site_id: Optional[in
rows: List[Tuple[db.Participation, db.Solution]] = q.all() rows: List[Tuple[db.Participation, db.Solution]] = q.all()
rows.sort(key=lambda r: r[0].user.sort_key()) rows.sort(key=lambda r: r[0].user.sort_key())
if request.method == 'POST' and 'download' in request.form: download_form = DownloadButtonForm()
paper_ids = [sol.final_submit for pion, sol in rows if sol is not None and sol.final_submit is not None] if request.method == 'POST' and download_solutions(download_form, [sol for pion, sol in rows if sol is not None], f'úlohy {sc.task.code}'):
mo.jobs.submit.schedule_download_submits(paper_ids, f'Odevzdaná řešení úlohy {sc.task.code}', g.user)
flash('Příprava řešení ke stažení zahájena.', 'success')
return redirect(url_for('org_jobs')) return redirect(url_for('org_jobs'))
# Count papers for each solution # Count papers for each solution
...@@ -725,6 +745,7 @@ def org_contest_task_submits(contest_id: int, task_id: int, site_id: Optional[in ...@@ -725,6 +745,7 @@ def org_contest_task_submits(contest_id: int, task_id: int, site_id: Optional[in
sc=sc, rows=rows, paper_counts=paper_counts, sc=sc, rows=rows, paper_counts=paper_counts,
db=db, # kvůli hodnotám enumů db=db, # kvůli hodnotám enumů
paper_link=paper_link, paper_link=paper_link,
download_form=download_form,
) )
...@@ -825,10 +846,8 @@ def org_contest_solutions(id: int, site_id: Optional[int] = None): ...@@ -825,10 +846,8 @@ def org_contest_solutions(id: int, site_id: Optional[int] = None):
): ):
paper_counts[(user_id, task_id, type.name)] = count paper_counts[(user_id, task_id, type.name)] = count
if request.method == 'POST' and 'download' in request.form: download_form = DownloadButtonForm()
paper_ids = [sol.final_submit for sol in sols if sol is not None and sol.final_submit is not None] if request.method == 'POST' and download_solutions(download_form, [sol for sol in sols if sol is not None], sc.round.round_code()):
mo.jobs.submit.schedule_download_submits(paper_ids, 'Odevzdaná řešení', g.user)
flash('Příprava řešení ke stažení zahájena.', 'success')
return redirect(url_for('org_jobs')) return redirect(url_for('org_jobs'))
task_sols: Dict[int, Dict[int, db.Solution]] = {} task_sols: Dict[int, Dict[int, db.Solution]] = {}
...@@ -851,4 +870,5 @@ def org_contest_solutions(id: int, site_id: Optional[int] = None): ...@@ -851,4 +870,5 @@ def org_contest_solutions(id: int, site_id: Optional[int] = None):
can_edit_points=sc.allow_edit_points and sc.round.state == db.RoundState.grading, can_edit_points=sc.allow_edit_points and sc.round.state == db.RoundState.grading,
paper_link=paper_link, paper_link=paper_link,
db=db, # kvůli hodnotám enumů db=db, # kvůli hodnotám enumů
download_form=download_form,
) )
{% extends "base.html" %} {% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block body %} {% block body %}
{% set round = contest.round %} {% set round = contest.round %}
{% set site_id = site.place_id if site else None %} {% set site_id = site.place_id if site else None %}
...@@ -86,8 +87,6 @@ konkrétní úlohu. Symbol <b>+</b> značí, že existuje více verzí dostupný ...@@ -86,8 +87,6 @@ konkrétní úlohu. Symbol <b>+</b> značí, že existuje více verzí dostupný
{% endfor %} {% endfor %}
</table> </table>
<form method=POST action=""> {{ wtf.quick_form(download_form, form_type='basic') }}
<button type=submit name=download value=go>Stáhnout všechna řešení jako ZIP</button>
</form>
{% endblock %} {% endblock %}
{% extends "base.html" %} {% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block body %} {% block body %}
{% set contest = sc.contest %} {% set contest = sc.contest %}
{% set ct_id = contest.contest_id %} {% set ct_id = contest.contest_id %}
...@@ -88,8 +89,6 @@ naleznete v detailu řešení. ...@@ -88,8 +89,6 @@ naleznete v detailu řešení.
{% endfor %} {% endfor %}
</table> </table>
<form method=POST action=""> {{ wtf.quick_form(download_form, form_type='basic') }}
<button type=submit name=download value=go>Stáhnout všechna řešení jako ZIP</button>
</form>
{% endblock %} {% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment