forked from GithubBackups/healthchecks
Formatting of durations
This commit is contained in:
parent
16763fcde0
commit
4ccbac7e4a
@ -12,23 +12,6 @@ STATUSES = (("up", "Up"), ("down", "Down"), ("new", "New"))
|
||||
DEFAULT_TIMEOUT = td(days=1)
|
||||
DEFAULT_GRACE = td(hours=1)
|
||||
|
||||
DURATION_CHOICES = (
|
||||
("1 minute", td(minutes=1)),
|
||||
("2 minutes", td(minutes=2)),
|
||||
("5 minutes", td(minutes=5)),
|
||||
("10 minutes", td(minutes=10)),
|
||||
("15 minutes", td(minutes=15)),
|
||||
("30 minutes", td(minutes=30)),
|
||||
("1 hour", td(hours=1)),
|
||||
("3 hours", td(hours=3)),
|
||||
("6 hours", td(hours=6)),
|
||||
("12 hours", td(hours=12)),
|
||||
("1 day", td(days=1)),
|
||||
("2 days", td(days=2)),
|
||||
("3 days", td(days=3)),
|
||||
("1 week", td(weeks=1))
|
||||
)
|
||||
|
||||
|
||||
class Check(models.Model):
|
||||
name = models.CharField(max_length=100, blank=True)
|
||||
@ -46,7 +29,6 @@ class Check(models.Model):
|
||||
|
||||
def send_alert(self):
|
||||
ctx = {
|
||||
"timeout_choices": DURATION_CHOICES,
|
||||
"check": self,
|
||||
"checks": self.user.check_set.order_by("created"),
|
||||
"now": timezone.now()
|
||||
|
0
hc/front/templatetags/__init__.py
Normal file
0
hc/front/templatetags/__init__.py
Normal file
26
hc/front/templatetags/hc_extras.py
Normal file
26
hc/front/templatetags/hc_extras.py
Normal file
@ -0,0 +1,26 @@
|
||||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter
|
||||
def hc_duration(td):
|
||||
total = int(td.total_seconds() / 60)
|
||||
total, m = divmod(total, 60)
|
||||
total, h = divmod(total, 24)
|
||||
w, d = divmod(total, 7)
|
||||
|
||||
result = ""
|
||||
if w:
|
||||
result += "1 week " if w == 1 else "%d weeks " % w
|
||||
|
||||
if d:
|
||||
result += "1 day " if d == 1 else "%d days " % d
|
||||
|
||||
if h:
|
||||
result += "1 hour " if h == 1 else "%d hours " % h
|
||||
|
||||
if m:
|
||||
result += "1 minute " if m == 1 else "%d minutes " % m
|
||||
|
||||
return result
|
@ -5,7 +5,7 @@ from django.http import HttpResponseForbidden
|
||||
from django.shortcuts import redirect, render
|
||||
from django.utils import timezone
|
||||
|
||||
from hc.api.models import Check, DURATION_CHOICES
|
||||
from hc.api.models import Check
|
||||
from hc.front.forms import TimeoutForm
|
||||
|
||||
|
||||
@ -43,8 +43,7 @@ def _my_checks(request):
|
||||
|
||||
ctx = {
|
||||
"checks": checks,
|
||||
"now": timezone.now(),
|
||||
"duration_choices": DURATION_CHOICES
|
||||
"now": timezone.now()
|
||||
}
|
||||
|
||||
return render(request, "front/my_checks.html", ctx)
|
||||
@ -121,11 +120,9 @@ def email_preview(request, code):
|
||||
if check.user != request.user:
|
||||
return HttpResponseForbidden()
|
||||
|
||||
from hc.api.models import TIMEOUT_CHOICES
|
||||
ctx = {
|
||||
"check": check,
|
||||
"checks": check.user.check_set.all(),
|
||||
"timeout_choices": TIMEOUT_CHOICES,
|
||||
"now": timezone.now()
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{% load humanize %}
|
||||
{% load humanize hc_extras %}
|
||||
|
||||
<style>
|
||||
th {
|
||||
@ -68,11 +68,7 @@
|
||||
<code>{{ check.url }}</code>
|
||||
</td>
|
||||
<td>
|
||||
{% for label, value in timeout_choices %}
|
||||
{% if check.timeout == value %}
|
||||
{{ label }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{{ check.timeout|hc_duration }}
|
||||
</td>
|
||||
<td>
|
||||
{% if check.last_ping %}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
{% load humanize staticfiles %}
|
||||
{% load humanize staticfiles hc_extras %}
|
||||
|
||||
{% block title %}My Checks - healthchecks.io{% endblock %}
|
||||
|
||||
@ -51,18 +51,10 @@
|
||||
data-timeout="{{ check.timeout.total_seconds }}"
|
||||
data-grace="{{ check.grace.total_seconds }}"
|
||||
class="timeout_grace">
|
||||
{% for label, value in duration_choices %}
|
||||
{% if check.timeout == value %}
|
||||
{{ label }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{{ check.timeout|hc_duration }}
|
||||
<br />
|
||||
<span class="checks-subline">
|
||||
{% for label, value in duration_choices %}
|
||||
{% if check.grace == value %}
|
||||
{{ label }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{{ check.grace|hc_duration }}
|
||||
</span>
|
||||
</span>
|
||||
</td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user