diff --git a/www/maposmatic/templatetags/extratags.py b/www/maposmatic/templatetags/extratags.py index 0e7a302c..100f432c 100644 --- a/www/maposmatic/templatetags/extratags.py +++ b/www/maposmatic/templatetags/extratags.py @@ -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+= "

%s!

" % value.resultmsg # TODO localize the result messages + + error_log_tail = escape(_lastline(value.get_errorlog_file())).replace(':',':
') + if error_log_tail: + result+= _("Check the %(error_log)s for more details
") % { + 'error_log': " %s" % (value.get_errorlog(), _("error log")), + } + if www.settings.CONTACT_EMAIL: - return mark_safe(_alert_err - + str(("

%(msg)s!

" - + str(_("Please check the %(error_log)s for more details
or contact %(email)s for more information."))) - % { - 'msg': value.resultmsg, - 'email': " %s" % (www.settings.CONTACT_EMAIL, value.id, www.settings.CONTACT_EMAIL), - 'error_log': " %s" % (value.get_errorlog(), _("error log")), - } - ) - + "
"+_lastline(value.get_errorlog_file()).replace(':',':
')+"
" - + _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': " %(email)s" % { + "email": www.settings.CONTACT_EMAIL, + "id": value.id + } + } + + if error_log_tail: + result+= "
%s" % 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)