Commit f87d9f4c authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

render the job status with a template filter

This makes much less code (and possibly less bugs!)

Also I did two other changes:

- removed the "result" field from the template and use the 'status'
  field instead. Actually the status is what we display to the user (the
  'state' and 'result' fields are internal to allgo).

  The status is the textual representation of:
  - the 'result' field if the job is terminated (success, error, timeout
    or aborted)
  - the 'state' field otherwise (new, waiting, running, aborting)

- changed the colors of the waiting and timeout state
  - waiting:  orange -> yellow
  - timeout:  yellow -> orange
  The rationale is that 'waiting' is a more normal state than
  'timeout' (thus the timeout color should be closer to red)

- introduce a separate icon for the 'aborting' state (orange fa-play)
parent 96e19513
Pipeline #30227 failed with stage
in 46 seconds
......@@ -360,6 +360,22 @@ class Job(TimeStampModel):
class Meta:
db_table = 'dj_jobs'
@property
def status(self):
"""Return a textual representation of the job status
The job status is what we display to the user (the 'state' and 'result'
fields are internal to allgo).
The status is the textual representation of:
- the 'result' field if the job is terminated (success, error, timeout
or aborted)
- the 'state' field otherwise (new, waiting, running, aborting)
"""
return (self.get_result_display
if self.state in (Job.DONE, Job.ARCHIVED)
else self.get_state_display)()
# def __str__(self):
# return self.webapp
......
from django import template
from django.utils.safestring import mark_safe
from misaka import Markdown, HtmlRenderer
from main.models import Job
register = template.Library()
......@@ -37,3 +40,32 @@ def email2name(email):
def fancy_name(webapp_name):
""" Replace underscores by spaces """
return webapp_name.replace('_', ' ')
_JOB_STATUS_RENDER_VALUES = {
"NEW": ("New job", "fas fa-plus picto-green"),
"WAITING": ("Waiting job", "fas fa-clock picto-yellow"),
"RUNNING": ("Job running", "fas fa-play picto-blue"),
"ABORTING": ("Job aborting", "fas fa-play picto-orange"),
"SUCCESS": ("Job success", "fas fa-check picto-green"),
"ERROR": ("Job error", "fas fa-times picto-red"),
"ABORTED": ("Job aborted", "fas fa-ban picto-red"),
"TIMEOUT": ("Job timeout", "fas fa-stopwatch picto-orange"),
}
@register.filter(name='status_icon')
def status_icon(obj):
""" Renders a status icon for a model """
def render_job_status(status):
txt, cls = _JOB_STATUS_RENDER_VALUES.get(status,
("Unknown status", "fas fa-question"))
return ('<i class="{cls}" data-toggle="tooltip" data-placement="top"'
' title="{txt}"></i><span class="text-hide">{txt}</span>'
.format(txt=txt, cls=cls))
if isinstance(obj, Job):
return mark_safe(render_job_status(obj.status))
raise TypeError(type(obj))
......@@ -95,83 +95,7 @@
</tr>
<tr>
<td class="text-muted">Status</td>
<td>
{% if job.state == 0 %}
<i class="fas fa-plus picto-green"
data-toggle="tooltip"
data-placement="top"
title="New job"
></i><span class="text-hide">New job</span>
{% elif job.state == 1 %}
<i class="fas fa-clock picto-orange"
data-toggle="tooltip"
data-placement="top"
title="Job waiting"
></i><span class="text-hide">Waiting job</span>
{% elif job.state == 2 %}
<i class="fas fa-play picto-yellow"
data-toggle="tooltip"
data-placement="top"
title="Job running"
></i><span class="text-hide">Job running</span>
{% elif job.state == 3 %}
<i class="fas fa-check picto-green"
data-toggle="tooltip"
data-placement="top"
title="Job Done"
></i><span class="text-hide">Job done</span>
{% elif job.state == 4 %}
<i class="fas fa-archive"
data-toggle="tooltip"
data-placement="top"
title="Job archived"
></i><span class="text-hide">Job archived</span>
{% elif job.state == 5 %}
<i class="fas fa-eraser picto-orange"
data-toggle="tooltip"
data-placement="top"
title="Job deleted"
></i><span class="text-hide">Job deleted</span>
{% else %}
<i class="fas fa-ban picto-red"
data-toggle="tooltip"
data-placement="top"
title="Job aborted"
></i><span class="text-hide">Job aborted</span>
{% endif %}
</td>
</tr>
<tr>
<td class="text-muted">Result</td>
<td>
{% if job.result == 0 %}
in progress
{% elif job.result == 1 %}
<i class="fas fa-check"
data-toggle="tooltip"
data-placement="top"
title="Result successful"
style="color: green;"></i><span class="text-hide">Result successful</span>
{% elif job.result == 2 %}
<i class="fas fa-times"
data-toggle="tooltip"
data-placement="top"
title="Result error"
style="color: red;"></i><span class="text-hide">Result error</span>
{% elif job.result == 3 %}
<i class="fas fa-ban"
data-toggle="tooltip"
data-placement="top"
title="Result aborted"
style="color: orange;"></i><span class="text-hide">Result aborted</span>
{% elif job.result == 4 %}
<i class="fas fa-stopwatch"
data-toggle="tooltip"
data-placement="top"
title="Timeout"
style="color: orange;"></i><span class="text-hide">Timeout</span>
{% endif %}
</td>
<td>{{ job | status_icon }}</td>
</tr>
</table>
</div>
......
......@@ -34,51 +34,7 @@
<td>{{ job.version }}</td>
<td>{{ job.param }}</td>
<td>{{ job.queue.name }}</td>
<td class="text-center">
{% if job.state == 0 %}
<i class="fas fa-plus"
data-toggle="tooltip"
data-placement="top"
title="New job"
style="color: green;"></i><span class="text-hide">New job</span>
{% elif job.state == 1 %}
<i class="fas fa-clock"
data-toggle="tooltip"
data-placement="top"
title="Job waiting"
style="color: orange;"></i><span class="text-hide">Waiting job</span>
{% elif job.state == 2 %}
<i class="fas fa-play"
data-toggle="tooltip"
data-placement="top"
title="Job running"
style="color: blue;"></i><span class="text-hide">Job running</span>
{% elif job.state == 3 %}
<i class="fas fa-check"
data-toggle="tooltip"
data-placement="top"
title="Job Done"
style="color: green;"></i><span class="text-hide">Job done</span>
{% elif job.state == 4 %}
<i class="fas fa-archive"
data-toggle="tooltip"
data-placement="top"
title="Job archived"
></i><span class="text-hide">Job archived</span>
{% elif job.state == 5 %}
<i class="fas fa-eraser"
data-toggle="tooltip"
data-placement="top"
title="Job deleted"
style="color: orange;"></i><span class="text-hide">Job deleted</span>
{% else %}
<i class="fas fa-ban"
data-toggle="tooltip"
data-placement="top"
title="Job aborted"
style="color: red;"></i><span class="text-hide">Job aborted</span>
{% endif %}
</td>
<td class="text-center">{{ job | status_icon }}</td>
<td class="text-center">
<a href="{% url 'main:job_delete' job.id %}" class="btn btn-danger"
data-toggle="tooltip"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment