diff --git a/mo/web/org_jobs.py b/mo/web/org_jobs.py index 30d61eeb0802c28232b9882aaae807d0b768bc8e..7b5c6accd76ad96c657849119d969b75da8ff0fb 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 0000000000000000000000000000000000000000..42ae2f4577485e9fd159ec306a8c2d1f2bbf751a --- /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 746b3f4048d1d490cfe9c9f8d01ba34eae4586ca..8ab206043c5e29d70e2c11a2c3cc40cc057d813a 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 %}