summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJelle van der Waa <jelle@vdwaa.nl>2016-10-21 22:19:46 +0200
committerJelle van der Waa <jelle@vdwaa.nl>2017-05-02 21:13:56 +0200
commit6489bd1a2e6faeff624efa93fa6f1b6f6535ca97 (patch)
tree9653704b927dc53e9453d6a510229db0f99ea5c5
parent7ce890eb18a8d7e17c4eacc760e2cc1ce4608a70 (diff)
downloadarchweb-6489bd1a2e6faeff624efa93fa6f1b6f6535ca97.tar.gz
archweb-6489bd1a2e6faeff624efa93fa6f1b6f6535ca97.zip
Port mirrors to pure django template
-rw-r--r--main/templatetags/flags.py37
-rw-r--r--templates/mirrors/error_table.html (renamed from templates/mirrors/error_table.html.jinja)10
-rw-r--r--templates/mirrors/mirror_details.html4
-rw-r--r--templates/mirrors/mirror_details_urls.html (renamed from templates/mirrors/mirror_details_urls.html.jinja)18
-rw-r--r--templates/mirrors/status.html6
-rw-r--r--templates/mirrors/status_table.html29
-rw-r--r--templates/mirrors/status_table.html.jinja28
-rw-r--r--templates/mirrors/url_details_logs.html.jinja10
8 files changed, 93 insertions, 49 deletions
diff --git a/main/templatetags/flags.py b/main/templatetags/flags.py
index 5b356561..d50ee51d 100644
--- a/main/templatetags/flags.py
+++ b/main/templatetags/flags.py
@@ -1,3 +1,4 @@
+from datetime import timedelta
from django import template
register = template.Library()
@@ -10,4 +11,40 @@ def country_flag(country):
return '<span class="fam-flag fam-flag-%s" title="%s"></span> ' % (
unicode(country.code).lower(), unicode(country.name))
+@register.filter
+def percentage(value, arg=1):
+ if not value and type(value) != float:
+ return u''
+ new_val = value * 100.0
+ return '%.*f%%' % (arg, new_val)
+
+@register.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)
+
+@register.filter
+def floatvalue(value, arg=2):
+ if value is None:
+ return u''
+ return '%.*f' % (arg, value)
+
+
+@register.filter
+def hours(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)
+ if hrs == 1:
+ return '%d hour' % hrs
+ return '%d hours' % hrs
+
# vim: set ts=4 sw=4 et:
diff --git a/templates/mirrors/error_table.html.jinja b/templates/mirrors/error_table.html
index 132aae63..03de4944 100644
--- a/templates/mirrors/error_table.html.jinja
+++ b/templates/mirrors/error_table.html
@@ -1,3 +1,5 @@
+{% load flags %}
+
<table id="errorlog_mirrors" class="results">
<thead>
<tr>
@@ -11,14 +13,14 @@
</tr>
</thead>
<tbody>
- {% for log in error_logs %}<tr class="{{ loop.cycle('odd', 'even') }}">
+ {% for log in error_logs %}<tr class="{% cycle 'odd' 'even' %}">
<td>{{ log.url.url }}</td>
<td>{{ log.url.protocol.protocol }}</td>
- <td class="country">{{ country_flag(log.url.country) }}{{ log.url.country.name }}</td>
+ <td class="country">{% country_flag log.url.country %}{{ log.url.country.name }}</td>
<td class="wrap">{{ log.error|linebreaksbr }}</td>
- <td>{{ log.last_occurred|date('Y-m-d H:i') }}</td>
+ <td>{{ log.last_occurred|date:'Y-m-d H:i' }}</td>
<td>{{ log.error_count }}</td>
- <td><a href="{{ log.url.get_absolute_url() }}">details</a></td>
+ <td><a href="{{ log.url.get_absolute_url }}">details</a></td>
</tr>{% endfor %}
</tbody>
</table>
diff --git a/templates/mirrors/mirror_details.html b/templates/mirrors/mirror_details.html
index 64009380..401a57e7 100644
--- a/templates/mirrors/mirror_details.html
+++ b/templates/mirrors/mirror_details.html
@@ -93,10 +93,10 @@
</table>
<h3>Available URLs</h3>
- {% include "mirrors/mirror_details_urls.html.jinja" %}
+ {% include "mirrors/mirror_details_urls.html" %}
<h3>Error Log</h3>
- {% include "mirrors/error_table.html.jinja" %}
+ {% include "mirrors/error_table.html" %}
</div>
<div class="box">
diff --git a/templates/mirrors/mirror_details_urls.html.jinja b/templates/mirrors/mirror_details_urls.html
index 7ab1548b..4cada31e 100644
--- a/templates/mirrors/mirror_details_urls.html.jinja
+++ b/templates/mirrors/mirror_details_urls.html
@@ -1,3 +1,5 @@
+{% load flags %}
+
<table id="available_urls" class="results">
<thead>
<tr>
@@ -17,18 +19,18 @@
</thead>
<tbody>
{% for m_url in urls %}
- <tr class="{{ loop.cycle('odd', 'even') }}">
+ <tr class="{% cycle 'odd' 'even' %}">
<td>{% if m_url.protocol.is_download %}<a href="{{ m_url.url }}">{{ m_url.url }}</a>{% else %}{{ m_url.url }}{% endif %}</td>
<td>{{ m_url.protocol }}</td>
- <td class="country">{{ country_flag(m_url.country) }}{{ m_url.country.name }}</td>
+ <td class="country">{% country_flag m_url.country %}{{ m_url.country.name }}</td>
<td>{{ m_url.has_ipv4|yesno|capfirst }}</td>
<td>{{ m_url.has_ipv6|yesno|capfirst }}</td>
- <td>{{ m_url.last_sync|date('Y-m-d H:i')|default('unknown') }}</td>
- <td>{{ m_url.completion_pct|percentage(1) }}</td>
- <td>{{ m_url.delay|duration|default('unknown') }}</td>
- <td>{{ m_url.duration_avg|floatvalue(2) }}</td>
- <td>{{ m_url.duration_stddev|floatvalue(2) }}</td>
- <td>{{ m_url.score|floatvalue(1)|default('∞') }}</td>
+ <td>{{ m_url.last_sync|date:'Y-m-d H:i'|default:'unknown' }}</td>
+ <td>{{ m_url.completion_pct|percentage:1 }}</td>
+ <td>{{ m_url.delay|duration|default:'unknown' }}</td>
+ <td>{{ m_url.duration_avg|floatvalue:2 }}</td>
+ <td>{{ m_url.duration_stddev|floatvalue:2 }}</td>
+ <td>{{ m_url.score|floatvalue:1|default:'∞' }}</td>
<td><a href="{{ m_url.id }}/">Details</a></td>
</tr>
{% endfor %}
diff --git a/templates/mirrors/status.html b/templates/mirrors/status.html
index 530e3ff5..24408be7 100644
--- a/templates/mirrors/status.html
+++ b/templates/mirrors/status.html
@@ -60,18 +60,18 @@
<a name="outofsync" id="outofsync"></a>
<h3>Out of Sync Mirrors</h3>
{% with urls=bad_urls table_id='outofsync_mirrors' %}
- {% include "mirrors/status_table.html.jinja" %}
+ {% include "mirrors/status_table.html" %}
{% endwith %}
<a name="successful" id="successful"></a>
<h3>Successfully Syncing Mirrors</h3>
{% with urls=good_urls table_id='successful_mirrors' %}
- {% include "mirrors/status_table.html.jinja" %}
+ {% include "mirrors/status_table.html" %}
{% endwith %}
<a name="errorlog" id="errorlog"></a>
<h3>Mirror Syncing Error Log</h3>
- {% include "mirrors/error_table.html.jinja" %}
+ {% include "mirrors/error_table.html" %}
</div>
{% endblock %}
diff --git a/templates/mirrors/status_table.html b/templates/mirrors/status_table.html
new file mode 100644
index 00000000..3f8cd2d9
--- /dev/null
+++ b/templates/mirrors/status_table.html
@@ -0,0 +1,29 @@
+{% load flags %}
+<table id="{{ table_id }}" class="results">
+ <thead>
+ <tr>
+ <th>Mirror URL</th>
+ <th>Protocol</th>
+ <th>Country</th>
+ <th>Completion %</th>
+ <th>μ Delay (hh:mm)</th>
+ <th>μ Duration (s)</th>
+ <th>σ Duration (s)</th>
+ <th>Mirror Score</th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for m_url in urls %}<tr class="{% cycle 'odd' 'even' }}">
+ <td>{{ m_url.url }}</td>
+ <td>{{ m_url.protocol }}</td>
+ <td class="country">{% country_flag m_url.country %}{{ m_url.country.name }}</td>
+ <td>{{ m_url.completion_pct|percentage:1 }}</td>
+ <td>{{ m_url.delay|duration|default:unknown }}</td>
+ <td>{{ m_url.duration_avg|floatvalue:2 }}</td>
+ <td>{{ m_url.duration_stddev|floatvalue:2 }}</td>
+ <td>{{ m_url.score|floatvalue:1|default:'∞' }}</td>
+ <td><a href="{{ m_url.get_absolute_url }}">details</a></td>
+ </tr>{% endfor %}
+ </tbody>
+</table>
diff --git a/templates/mirrors/status_table.html.jinja b/templates/mirrors/status_table.html.jinja
deleted file mode 100644
index 598a1af0..00000000
--- a/templates/mirrors/status_table.html.jinja
+++ /dev/null
@@ -1,28 +0,0 @@
-<table id="{{ table_id }}" class="results">
- <thead>
- <tr>
- <th>Mirror URL</th>
- <th>Protocol</th>
- <th>Country</th>
- <th>Completion %</th>
- <th>μ Delay (hh:mm)</th>
- <th>μ Duration (s)</th>
- <th>σ Duration (s)</th>
- <th>Mirror Score</th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- {% for m_url in urls %}<tr class="{{ loop.cycle('odd', 'even') }}">
- <td>{{ m_url.url }}</td>
- <td>{{ m_url.protocol }}</td>
- <td class="country">{{ country_flag(m_url.country) }}{{ m_url.country.name }}</td>
- <td>{{ m_url.completion_pct|percentage(1) }}</td>
- <td>{{ m_url.delay|duration|default('unknown') }}</td>
- <td>{{ m_url.duration_avg|floatvalue(2) }}</td>
- <td>{{ m_url.duration_stddev|floatvalue(2) }}</td>
- <td>{{ m_url.score|floatvalue(1)|default('∞') }}</td>
- <td><a href="{{ m_url.get_absolute_url() }}">details</a></td>
- </tr>{% endfor %}
- </tbody>
-</table>
diff --git a/templates/mirrors/url_details_logs.html.jinja b/templates/mirrors/url_details_logs.html.jinja
index 51f54931..a87e58d4 100644
--- a/templates/mirrors/url_details_logs.html.jinja
+++ b/templates/mirrors/url_details_logs.html.jinja
@@ -1,3 +1,5 @@
+{% load flags %}
+
<table id="check_logs" class="results">
<thead>
<tr>
@@ -12,11 +14,11 @@
</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">{% if log.location %}{{ country_flag(log.location.country) }}{{ log.location.country.name }}{% else %}Unknown{% endif %}</td>
+ {% for log in logs %}<tr class="{% cycle 'odd' 'even' %}">
+ <td>{{ log.check_time|date:'Y-m-d H:i' }}</td>
+ <td class="country">{% if log.location %}{% country_flag log.location.country %}{{ log.location.country.name }}{% else %}Unknown{% endif %}</td>
<td>{% if log.location %}{{ log.location.source_ip }}{% else %}Unknown{% endif %}</td>
- <td>{{ log.last_sync|date('Y-m-d H:i') }}</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>