From 336084a356f200fc96e6433dbecbfb64a6dbe69d Mon Sep 17 00:00:00 2001 From: Martin Mares <mj@ucw.cz> Date: Sat, 16 Jan 2021 01:40:20 +0100 Subject: [PATCH] UI k uploadu feedbacku --- mo/web/org_contest.py | 32 +++++++++++++++++++- mo/web/templates/org_contest_solutions.html | 2 +- mo/web/templates/org_contest_task.html | 2 +- mo/web/templates/org_upload_feedback.html | 11 +++++++ mo/web/templates/parts/org_sol_download.html | 10 ++++++ 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 mo/web/templates/org_upload_feedback.html create mode 100644 mo/web/templates/parts/org_sol_download.html diff --git a/mo/web/org_contest.py b/mo/web/org_contest.py index 1583d052..26df8205 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 b3cabb55..d045f70f 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 10275623..b17b0f1c 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 00000000..651ffe16 --- /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 00000000..ebe1a405 --- /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> -- GitLab