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_TIMEOUT = td(days=1)
|
||||||
DEFAULT_GRACE = td(hours=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):
|
class Check(models.Model):
|
||||||
name = models.CharField(max_length=100, blank=True)
|
name = models.CharField(max_length=100, blank=True)
|
||||||
@ -46,7 +29,6 @@ class Check(models.Model):
|
|||||||
|
|
||||||
def send_alert(self):
|
def send_alert(self):
|
||||||
ctx = {
|
ctx = {
|
||||||
"timeout_choices": DURATION_CHOICES,
|
|
||||||
"check": self,
|
"check": self,
|
||||||
"checks": self.user.check_set.order_by("created"),
|
"checks": self.user.check_set.order_by("created"),
|
||||||
"now": timezone.now()
|
"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.shortcuts import redirect, render
|
||||||
from django.utils import timezone
|
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
|
from hc.front.forms import TimeoutForm
|
||||||
|
|
||||||
|
|
||||||
@ -43,8 +43,7 @@ def _my_checks(request):
|
|||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"checks": checks,
|
"checks": checks,
|
||||||
"now": timezone.now(),
|
"now": timezone.now()
|
||||||
"duration_choices": DURATION_CHOICES
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, "front/my_checks.html", ctx)
|
return render(request, "front/my_checks.html", ctx)
|
||||||
@ -121,11 +120,9 @@ def email_preview(request, code):
|
|||||||
if check.user != request.user:
|
if check.user != request.user:
|
||||||
return HttpResponseForbidden()
|
return HttpResponseForbidden()
|
||||||
|
|
||||||
from hc.api.models import TIMEOUT_CHOICES
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"check": check,
|
"check": check,
|
||||||
"checks": check.user.check_set.all(),
|
"checks": check.user.check_set.all(),
|
||||||
"timeout_choices": TIMEOUT_CHOICES,
|
|
||||||
"now": timezone.now()
|
"now": timezone.now()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{% load humanize %}
|
{% load humanize hc_extras %}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
th {
|
th {
|
||||||
@ -68,11 +68,7 @@
|
|||||||
<code>{{ check.url }}</code>
|
<code>{{ check.url }}</code>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% for label, value in timeout_choices %}
|
{{ check.timeout|hc_duration }}
|
||||||
{% if check.timeout == value %}
|
|
||||||
{{ label }}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if check.last_ping %}
|
{% if check.last_ping %}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load humanize staticfiles %}
|
{% load humanize staticfiles hc_extras %}
|
||||||
|
|
||||||
{% block title %}My Checks - healthchecks.io{% endblock %}
|
{% block title %}My Checks - healthchecks.io{% endblock %}
|
||||||
|
|
||||||
@ -51,18 +51,10 @@
|
|||||||
data-timeout="{{ check.timeout.total_seconds }}"
|
data-timeout="{{ check.timeout.total_seconds }}"
|
||||||
data-grace="{{ check.grace.total_seconds }}"
|
data-grace="{{ check.grace.total_seconds }}"
|
||||||
class="timeout_grace">
|
class="timeout_grace">
|
||||||
{% for label, value in duration_choices %}
|
{{ check.timeout|hc_duration }}
|
||||||
{% if check.timeout == value %}
|
|
||||||
{{ label }}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
<br />
|
<br />
|
||||||
<span class="checks-subline">
|
<span class="checks-subline">
|
||||||
{% for label, value in duration_choices %}
|
{{ check.grace|hc_duration }}
|
||||||
{% if check.grace == value %}
|
|
||||||
{{ label }}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user