refactor map request status output

django-3.2
Hartmut Holzgraefe 2023-09-29 21:04:39 +00:00
rodzic 699c701339
commit d97f334b4e
4 zmienionych plików z 78 dodań i 73 usunięć

Wyświetl plik

@ -11,13 +11,13 @@
{% with date=map.submission_time|date:"DATETIME_FORMAT" %}
<tr><td><strong>{% trans "Request submitted" %}</strong></td><td title="{{ date }}">{% blocktrans with map.submission_time|timesince as since %}{{since}} ago{% endblocktrans %}</td></tr>
{% endwith %}
{% if map.is_rendering %}
{% with date=map.startofrendering_time|date:"DATETIME_FORMAT" duration=map.submission_time|timesince:map.startofrendering_time %}
<tr><td><strong>{% trans "Rendering started" %}</strong></td><td title="{{ date }}">{% blocktrans with map.submission_time|timesince as since %}{{since}} ago{% endblocktrans %}, {% blocktrans %}after {{ duration}} in the queue{% endblocktrans %}</td></tr>
{% endwith %}
{% endif %}
{% if map.is_done or map.is_obsolete %}
{% with date=map.startofrendering_time|date:"DATETIME_FORMAT" duration=map.submission_time|timesince:map.startofrendering_time %}
<tr><td><strong>{% trans "Rendering started" %}</strong></td><td title="{{ date }}">{% blocktrans with map.startofrendering_time|timesince as since %}{{since}} ago{% endblocktrans %}, {% blocktrans %}after {{ duration}} in the queue{% endblocktrans %}</td></tr>
@ -26,29 +26,67 @@
<tr><td><strong>{% trans "Rendering completed" %}</strong></td><td title="{{ date }}">{% blocktrans with map.endofrendering_time|timesince as since %}{{since}} ago{% endblocktrans %}, {% blocktrans %}after {{ duration }} {% endblocktrans %}</td></tr>
{% endwith %}
{% endif %}
{% if map.is_cancelled %}
{% with map.endofrendering_time|date:"DATETIME_FORMAT" as date %}
<tr><td><strong>{% trans "Rendering cancelled" %}</strong></td><td>{{ date }}</td></tr>
{% endwith %}
{% endif %}
</table>
<div>
{{ map|job_status_to_str }}
{% if map.status == 0 %}
<div class='alert alert-info' role='alert'>
<span class='spinner-border spinner-border-sm text-primary'></span>&nbsp;
{% blocktrans with counter=map.current_position_in_queue %}
Waiting for rendering to begin, {{ counter }} jobs still ahead of us
{% endblocktrans %}
</div>
{% elif map.status == 1 %}
<div class='alert alert-info' role='alert'>
<span class='spinner-border spinner-border-sm text-primary'></span>&nbsp;
{{ map.renderstep }}
</div>
{% elif map.status == 2 %}
{% if map.resultmsg == "ok" %}
<div class='alert alert-info' role='alert'>
{% trans "Rendering was successful." %}
</div>
{% else %}
<div class='alert alert-danger' role='alert'>
<h4><i class='fas fa-triangle-exclamation'></i> <b>{{ map.resultmsg }}</b></h4>
{% if not map.resultmsg|startswith:'Not enough memory' %}
{% if map|error_log_tail %}
{% blocktrans with url=map.get_errorlog %}
Check the <a target='_blank' href='{{ url }}'><i class='fas fa-file-lines'></i> error log</a> for more details<br>
{% endblocktrans %}
{% if settings.CONTACT_EMAIL %}
{% blocktrans with email=map|email_url %}
or contact {{ email }} for more information.
{% endblocktrans %}
{% endif %}
<hr><tt>{{ map|error_log_tail }}</tt>
{% endif %}
{% endif %}
</div>
{% endif %}
{% elif map.status == 3 %}
<div class='alert alert-warning' role='alert'>
{% if map.resultmsg == "ok" %}
{% trans "Rendering is obsolete: the rendering was successful, but the files are no longer available." %}
{% else %}
{% trans "Obsolete failed rendering: the rendering failed, and the incomplete files have been removed." %}
{% endif %}
</div>
{% elif map.status == 4 %}
<div class='alert alert-warning' role='alert'>
{% trans "The rendering was cancelled by the user." %}
</div>
{% else %}
<div class='alert alert-danger' role='alert'>{% trans "Unknown status" %} '{{ map.status }}'</div>
{% endif %}
<div style="height: 2em"></div>
{% if map.is_waiting %}
<i class="fas fa-hourglass"></i> {% trans "Pending..." %}
{% endif %}
{% if map.is_rendering %}
<i class="fas fa-pen-to-square"></i> {% trans "Rendering..." %} {{ status }}
{% endif %}
{% if not map.needs_waiting %}
{% if not map.needs_waiting %}
<form method="post" action="{% url "recreate" %}">
<input type="hidden" name="id" value="{{ map.id }}" />
<button class="btn btn-primary tooltipped" align="right"
@ -111,7 +149,7 @@
{% endif %}
{% if map.needs_waiting %}
<span class="refresh-time pull-right">{% blocktrans %}Updating in <span>{{ refresh }}</span>s...{% endblocktrans %}</span>
<input id="refreshtime" type="hidden" value="{{ refresh }}"</input>
{% if map.is_waiting %}
{% if nonce == map.nonce %}
<div style="height: 2em"></div>

Wyświetl plik

@ -37,11 +37,15 @@
{% block extrajs %}
{% if map.needs_waiting %}
setInterval(function() {
var t = $('.refresh-time > span').text() - 1;
$('.refresh-time > span').text(t);
if (t == 0) {
$('.refresh-time').text('{% trans "Updating now..." %}');
$('#map-rendering-status').load("../../apis/rendering-status/{{ map.id }}")
var f = $('#refreshtime');
if (f.length) {
t = f.val();
if (t == 0) {
$('#map-rendering-status').load("../../apis/rendering-status/{{ map.id }}");
f.val(-42);
} else if (t > 0) {
f.val(t - 1);
}
}
}, 1000);
{% endif %}

Wyświetl plik

@ -44,6 +44,9 @@ from . import paper_tags, rss_feed_tags, job_tags
def add_blank_after_comma(value):
return value.replace(",",", ")
@register.filter('startswith')
def startswith(text, starts):
return text.startswith(starts)
register.filter('abs', lambda x: abs(x))
register.filter('getitem', lambda d,i: d.get(i,''))

Wyświetl plik

@ -9,12 +9,6 @@ from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django.utils.html import escape
_alert_ok = "<div class='alert alert-success' role='alert'>"
_alert_info = "<div class='alert alert-info' role='alert'>"
_alert_warn = "<div class='alert alert-warning' role='alert'>"
_alert_err = "<div class='alert alert-danger' role='alert'>"
_alert_end = "</div>"
def _lastline(filename):
try:
with open(filename, "rb") as file:
@ -26,50 +20,16 @@ def _lastline(filename):
return ""
@register.filter()
def job_status_to_str(value):
if value.status == 0:
return mark_safe(_alert_info + str(_("Waiting for rendering to begin, %d jobs still ahead of us") % value.current_position_in_queue()) + _alert_end)
elif value.status == 1:
return mark_safe(_alert_info + str(_("The rendering is in progress...")) + _alert_end)
elif value.status == 2:
if value.resultmsg == 'ok':
return mark_safe(_alert_ok + str(_("Rendering was successful.")) + _alert_end)
else:
# TODO properly templatize this
result = _alert_err
result+= "<h4><i class='fas fa-triangle-exclamation'></i> <b>%s!</b></h4>" % value.resultmsg # TODO localize the result messages
def error_log_tail(value):
error_log_tail = escape(_lastline(value.get_errorlog_file())).replace(':',':<br/>')
return mark_safe(error_log_tail)
@register.filter()
def email_url(value):
return mark_safe("<a href='mailto:%(email)s?subject=[MapOSMatic] Error on request %(id)d'><i class='fas fa-envelope'></i> %(email)s</a>" % {
"email": www.settings.CONTACT_EMAIL,
"id": value.id
})
if not value.resultmsg.startswith("Not enough memory"):
error_log_tail = escape(_lastline(value.get_errorlog_file())).replace(':',':<br/>')
if error_log_tail:
result+= _("Check the %(error_log)s for more details<br/>") % {
'error_log': "<a target='_blank' href='%s'><i class='fas fa-file-lines'></i> %s</a>" % (value.get_errorlog(), _("error log")),
}
if www.settings.CONTACT_EMAIL:
if error_log_tail:
result+= "or "
result+= _("contact %(email)s for more information.") % {
'email': "<a href='mailto:%(email)s?subject=[MapOSMatic] Error on request %(id)d'><i class='fas fa-envelope'></i> %(email)s</a>" % {
"email": www.settings.CONTACT_EMAIL,
"id": value.id
}
}
if error_log_tail:
result+= "<hr/><tt>%s</tt>" % error_log_tail
result += _alert_end
return mark_safe(result)
elif value.status == 3:
if value.resultmsg == 'ok':
return mark_safe(_alert_info + str(_("Rendering is obsolete: the rendering was successful, but the files are no longer available.")) + _alert_end)
else:
return mark_safe(_alert_warn + str(_("Obsolete failed rendering: the rendering failed, and the incomplete files have been removed.")) + _alert_end)
elif value == 4:
return mark_safe(_alert_warn + str(_("The rendering was cancelled by the user.")) + _alert_end)
return ''