clean up yesterdays error detail output code a bit

site-osm-baustelle
Hartmut Holzgraefe 2023-01-20 07:05:37 +00:00
rodzic 47eceb26b9
commit 972cbfb1e8
1 zmienionych plików z 28 dodań i 15 usunięć

Wyświetl plik

@ -29,6 +29,7 @@ import re
from django import template
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.utils.html import escape
import www.settings
@ -48,9 +49,9 @@ def _lastline(filename):
file.seek(-2, os.SEEK_END)
while file.read(1) != b'\n':
file.seek(-2, os.SEEK_CUR)
return str(file.readline().decode())
return str(file.readline().decode())
except:
return ""
return ""
@register.filter()
def job_status_to_str(value):
@ -62,20 +63,32 @@ def job_status_to_str(value):
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
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:
return mark_safe(_alert_err
+ str(("<h4><i class='fas fa-triangle-exclamation'></i> <b>%(msg)s!</b></h4>"
+ str(_("Please check the %(error_log)s for more details<br/>or contact %(email)s for more information.")))
% {
'msg': value.resultmsg,
'email': "<a href='mailto:%s?subject=Error on request %d'><i class='fas fa-envelope'></i> %s</a>" % (www.settings.CONTACT_EMAIL, value.id, www.settings.CONTACT_EMAIL),
'error_log': "<a target='_blank' href='%s'><i class='fas fa-file-lines'></i> %s</a>" % (value.get_errorlog(), _("error log")),
}
)
+ "<hr/><tt>"+_lastline(value.get_errorlog_file()).replace(':',':<br/>')+"</tt>"
+ _alert_end)
else:
return mark_safe( _alert_err + _str(_("%(arg)s! Please check the error log for more information.") % {'arg': value.resultmsg}) + _alert_end)
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 arg == 'ok':
return mark_safe(_alert_info + str(_("Rendering is obsolete: the rendering was successful, but the files are no longer available.")) + _alert_end)