From 9405aa0b5753794b80afccb20632660a1376ac80 Mon Sep 17 00:00:00 2001 From: Martin Mares <mj@ucw.cz> Date: Sat, 16 Jan 2021 15:03:18 +0100 Subject: [PATCH] =?UTF-8?q?Str=C3=A1nka=20s=20detaily=20jobu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mo/web/org_jobs.py | 21 +++++++++++++++++++++ mo/web/templates/org_job.html | 33 +++++++++++++++++++++++++++++++++ mo/web/templates/org_jobs.html | 2 ++ 3 files changed, 56 insertions(+) create mode 100644 mo/web/templates/org_job.html diff --git a/mo/web/org_jobs.py b/mo/web/org_jobs.py index 30d61eeb..7b5c6acc 100644 --- a/mo/web/org_jobs.py +++ b/mo/web/org_jobs.py @@ -50,6 +50,27 @@ def org_jobs(): ) +@app.route('/org/jobs/<int:id>/') +def org_job(id: int): + sess = db.get_session() + job = sess.query(db.Job).options(joinedload(db.Job.user)).get(id) + if job is None: + return werkzeug.exceptions.NotFound() + + if not (job.user_id == g.user.user_id or g.user.is_org): + return werkzeug.exceptions.Forbidden() + + has_errors = (job.state == db.JobState.failed + and isinstance(job.out_json, dict) + and 'errors' in job.out_json) + + return render_template( + 'org_job.html', + job=job, db=db, + has_errors=has_errors, + ) + + @app.route('/org/jobs/<int:id>/output') def org_job_output(id: int): sess = db.get_session() diff --git a/mo/web/templates/org_job.html b/mo/web/templates/org_job.html new file mode 100644 index 00000000..42ae2f45 --- /dev/null +++ b/mo/web/templates/org_job.html @@ -0,0 +1,33 @@ +{% extends "base.html" %} +{% block head %} + <meta http-equiv=refresh content=30> +{% endblock %} +{% block body %} +<h2>Dávka #{{ job.job_id }}</h2> + +<table class=data> + <tr><th>Název<td>{{ job.description }} + <tr><th>Vlastník<td>{{ job.user.full_name() }} + <tr><th>Stav<td>{{ job.state.friendly_name() }} + <tr><th>Zpráva<td>{{ job.result|or_dash }} + <tr><th>Vytvořena<td>{{ job.created_at|time_and_timedelta }} + <tr><th>Dokončena<td>{{ job.finished_at|time_and_timedelta }} + <tr><th>Vyprší<td>{{ job.expires_at|time_and_timedelta }} +</table> + +{% if has_errors %} +<h3>Chyby</h3> + +<pre><div class="alert alert-danger" role="alert">{{ "" -}} +{% for e in job.out_json['errors'] %} +{{ e }} +{% endfor %} +</div></pre> + +{% endif %} + +{% if job.out_file %} + <a class='btn btn-xs btn-primary' href='{{ url_for('org_job_output', id=job.job_id) }}'>Stáhnout výstup</a> +{% endif %} + +{% endblock %} diff --git a/mo/web/templates/org_jobs.html b/mo/web/templates/org_jobs.html index 746b3f40..8ab20604 100644 --- a/mo/web/templates/org_jobs.html +++ b/mo/web/templates/org_jobs.html @@ -31,11 +31,13 @@ dávku po stažení výstupu smažete sami – šetří to místo na serveru. <td>{{ j.description }} <td>{{ j.created_at|timeformat }} <td><b>{{ j.state.friendly_name() }}</b>{% if j.finished_at != None %} {{ j.finished_at|timedelta }}{% endif %} + {%- if j.result != "" %}<br>{{ j.result }}{% endif %} <td>{% if j.expires_at %}{{ j.expires_at|timedelta}}{% endif %} {% if g.user.is_admin %}<td>{{ j.user.full_name() }}{% endif %} <td> <div class='btn-group'><form action="" method="POST" class="btn-group"> {{ form_delete_job.csrf_token() }} + <a class='btn btn-xs btn-primary' href='{{ url_for('org_job', id=j.job_id) }}'>Detail</a> {% if j.out_file %} <a class='btn btn-xs btn-primary' href='{{ url_for('org_job_output', id=j.job_id) }}'>Výsledek</a> {% endif %} -- GitLab