diff options
-rw-r--r-- | mirrors/templatetags/jinja2.py | 31 | ||||
-rw-r--r-- | packages/templatetags/jinja2.py | 1 | ||||
-rw-r--r-- | templates/mirrors/url_details.html | 29 | ||||
-rw-r--r-- | templates/mirrors/url_details_logs.html.jinja | 28 |
4 files changed, 60 insertions, 29 deletions
diff --git a/mirrors/templatetags/jinja2.py b/mirrors/templatetags/jinja2.py new file mode 100644 index 00000000..5d47fe9b --- /dev/null +++ b/mirrors/templatetags/jinja2.py @@ -0,0 +1,31 @@ +from django_jinja import library +from markupsafe import Markup + + +@library.global_function +def country_flag(country): + if not country: + return '' + html = '<span class="fam-flag fam-flag-%s" title="%s"></span> ' % ( + unicode(country.code).lower(), unicode(country.name)) + return Markup(html) + + +@library.filter +def duration(value): + if not value and type(value) != timedelta: + return u'' + # does not take microseconds into account + total_secs = value.seconds + value.days * 24 * 3600 + mins = total_secs // 60 + hrs, mins = divmod(mins, 60) + return '%d:%02d' % (hrs, mins) + + +@library.filter +def floatvalue(value, arg=2): + if value is None: + return u'' + return '%.*f' % (arg, value) + +# vim: set ts=4 sw=4 et: diff --git a/packages/templatetags/jinja2.py b/packages/templatetags/jinja2.py index 22f9914b..88b59a96 100644 --- a/packages/templatetags/jinja2.py +++ b/packages/templatetags/jinja2.py @@ -68,5 +68,4 @@ def bug_report(package): } return link_encode(url, data) - # vim: set ts=4 sw=4 et: diff --git a/templates/mirrors/url_details.html b/templates/mirrors/url_details.html index 557a1b79..8b7646b8 100644 --- a/templates/mirrors/url_details.html +++ b/templates/mirrors/url_details.html @@ -1,5 +1,4 @@ {% extends "base.html" %} -{% load cycle from future %} {% load static from staticfiles %} {% load mirror_status %} {% load flags %} @@ -57,34 +56,8 @@ {% endif %} </table> - <h3>Check Logs</h3> + {% include "mirrors/url_details_logs.html.jinja" %} - <table id="check_logs" class="results"> - <thead> - <tr> - <th>Check Time</th> - <th>Check Location</th> - <th>Check IP</th> - <th>Last Sync</th> - <th>Delay (hh:mm)</th> - <th>Duration (s)</th> - <th>Success?</th> - <th>Error Message</th> - </tr> - </thead> - <tbody> - {% for log in logs %}<tr class="{% cycle 'odd' 'even' %}"> - <td>{{ log.check_time|date:'Y-m-d H:i' }}</td> - <td class="country">{% country_flag log.location.country %}{{ log.location.country.name }}</td> - <td>{{ log.location.source_ip }}</td> - <td>{{ log.last_sync|date:'Y-m-d H:i' }}</td> - <td>{{ log.delay|duration }}</td> - <td>{{ log.duration|floatvalue }}</td> - <td>{{ log.is_success|yesno|capfirst }}</td> - <td class="wrap">{{ log.error|linebreaksbr }}</td> - </tr>{% endfor %} - </tbody> - </table> </div> {% endblock %} diff --git a/templates/mirrors/url_details_logs.html.jinja b/templates/mirrors/url_details_logs.html.jinja new file mode 100644 index 00000000..8f7c5644 --- /dev/null +++ b/templates/mirrors/url_details_logs.html.jinja @@ -0,0 +1,28 @@ + <h3>Check Logs</h3> + + <table id="check_logs" class="results"> + <thead> + <tr> + <th>Check Time</th> + <th>Check Location</th> + <th>Check IP</th> + <th>Last Sync</th> + <th>Delay (hh:mm)</th> + <th>Duration (s)</th> + <th>Success?</th> + <th>Error Message</th> + </tr> + </thead> + <tbody> + {% for log in logs %}<tr class="{{ loop.cycle('odd', 'even') }}"> + <td>{{ log.check_time|date('Y-m-d H:i') }}</td> + <td class="country">{{ country_flag(log.location.country) }}{{ log.location.country.name }}</td> + <td>{{ log.location.source_ip }}</td> + <td>{{ log.last_sync|date('Y-m-d H:i') }}</td> + <td>{{ log.delay()|duration }}</td> + <td>{{ log.duration|floatvalue }}</td> + <td>{{ log.is_success|yesno|capfirst }}</td> + <td class="wrap">{{ log.error|linebreaksbr }}</td> + </tr>{% endfor %} + </tbody> + </table> |