diff --git a/mo/web/org_contest.py b/mo/web/org_contest.py index 1583d0520eaaa620fb3d0023fbde6b554a0785a0..26df8205bc38c3ae7d73b19af1c8e4ee5f2c38c5 100644 --- a/mo/web/org_contest.py +++ b/mo/web/org_contest.py @@ -189,7 +189,7 @@ class ParticipantsActionForm(FlaskForm): class DownloadButtonForm(FlaskForm): - download = wtforms.SubmitField('Stáhnout všechna řešení jako ZIP') + download = wtforms.SubmitField('Stáhnout řešení jako ZIP') download_feedback = wtforms.SubmitField('Stáhnout opravená jako ZIP') @@ -872,3 +872,33 @@ def org_contest_solutions(id: int, site_id: Optional[int] = None): db=db, # kvůli hodnotám enumů download_form=download_form, ) + + +class UploadFeedbackForm(FlaskForm): + file = flask_wtf.file.FileField("Soubor") + submit = wtforms.SubmitField('Odeslat') + + +@app.route('/org/contest/c/<int:id>/upload-feedback', methods=('GET', 'POST')) +def org_upload_feedback(id: int): + sc = get_solution_context(id, None, None, None) + if not sc.allow_upload_feedback: + raise werkzeug.exceptions.Forbidden() + + form = UploadFeedbackForm() + + if form.validate_on_submit(): + # FIXME: Viz komentář o efektivitě v user_contest_task + tmp_name = secrets.token_hex(16) + tmp_path = os.path.join(app.instance_path, 'tmp', tmp_name) + form.file.data.save(tmp_path) + + mo.jobs.submit.schedule_upload_feedback(sc.round, tmp_path, f'Nahrání opravených řešení {sc.round.round_code()}', g.user) + return redirect(url_for('org_jobs')) + + return render_template( + 'org_upload_feedback.html', + round=sc.round, + contest=sc.contest, + form=form, + ) diff --git a/mo/web/templates/org_contest_solutions.html b/mo/web/templates/org_contest_solutions.html index b3cabb555bd38813d4d0813389eaf3c63ddcf062..d045f70f785a66cc4fe378d23d2b8cd6982b09b1 100644 --- a/mo/web/templates/org_contest_solutions.html +++ b/mo/web/templates/org_contest_solutions.html @@ -87,6 +87,6 @@ konkrétní úlohu. Symbol <b>+</b> značí, že existuje více verzí dostupný {% endfor %} </table> -{{ wtf.quick_form(download_form, form_type='basic') }} +{% include "parts/org_sol_download.html" %} {% endblock %} diff --git a/mo/web/templates/org_contest_task.html b/mo/web/templates/org_contest_task.html index 10275623509f87f0d02139086cc35f85197aa62d..b17b0f1cb65a926eeae44fa7e036253c88669ea7 100644 --- a/mo/web/templates/org_contest_task.html +++ b/mo/web/templates/org_contest_task.html @@ -89,6 +89,6 @@ naleznete v detailu řešení. {% endfor %} </table> -{{ wtf.quick_form(download_form, form_type='basic') }} +{% include "parts/org_sol_download.html" %} {% endblock %} diff --git a/mo/web/templates/org_upload_feedback.html b/mo/web/templates/org_upload_feedback.html new file mode 100644 index 0000000000000000000000000000000000000000..651ffe164640123c2a27c270af350af3cdbe2bd1 --- /dev/null +++ b/mo/web/templates/org_upload_feedback.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% import "bootstrap/wtf.html" as wtf %} +{% block body %} + <h2> + <a href='{{ url_for('org_round', id=round.round_id) }}'>Kolo {{ round.round_code() }}</a> + » <a href='{{ url_for('org_contest', id=contest.contest_id) }}'>{{ contest.place.name }}</a> + » Nahrát opravená řešení + </h2> + + {{ wtf.quick_form(form, form_type='basic') }} +{% endblock %} diff --git a/mo/web/templates/parts/org_sol_download.html b/mo/web/templates/parts/org_sol_download.html new file mode 100644 index 0000000000000000000000000000000000000000..ebe1a405d9b05b02b6c01f029b1dbabbba4cb7a5 --- /dev/null +++ b/mo/web/templates/parts/org_sol_download.html @@ -0,0 +1,10 @@ +<form action="" method="POST" class="form form-basic" role="form"> + {{ download_form.csrf_token }} + <div class="form-group"> + {{ wtf.form_field(download_form.download, form_type='inline') }} + {{ wtf.form_field(download_form.download_feedback, form_type='inline') }} + {% if sc.site == None and sc.allow_upload_feedback %} + <a class='btn btn-default' href="{{ url_for('org_upload_feedback', id=sc.contest.contest_id) }}">Nahrát opravená řešení</a> + {% endif %} + </div> +</form>