forked from GithubBackups/healthchecks
Natural sort for check names, fixes #136.
Apply the user's chosen sort order in emails also.
This commit is contained in:
parent
e1d5fa8638
commit
882933668a
@ -141,12 +141,13 @@ class Profile(models.Model):
|
|||||||
path = reverse("hc-unsubscribe-reports", args=[self.user.username])
|
path = reverse("hc-unsubscribe-reports", args=[self.user.username])
|
||||||
unsub_link = "%s%s?token=%s" % (settings.SITE_ROOT, path, token)
|
unsub_link = "%s%s?token=%s" % (settings.SITE_ROOT, path, token)
|
||||||
|
|
||||||
# Sort checks by team name, then by email, and then by creation date:
|
# Sort checks by owner. Need this because will group by owner in
|
||||||
checks = checks.order_by(
|
# template.
|
||||||
"user__profile__team_name", "user__email", "created")
|
checks = checks.order_by("user_id")
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"checks": checks,
|
"checks": checks,
|
||||||
|
"sort": self.sort,
|
||||||
"now": timezone.now(),
|
"now": timezone.now(),
|
||||||
"unsub_link": unsub_link,
|
"unsub_link": unsub_link,
|
||||||
"notifications_url": self.notifications_url,
|
"notifications_url": self.notifications_url,
|
||||||
|
|||||||
@ -52,9 +52,18 @@ class Email(Transport):
|
|||||||
|
|
||||||
headers = {"X-Bounce-Url": bounce_url}
|
headers = {"X-Bounce-Url": bounce_url}
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Look up the sorting preference for this email address
|
||||||
|
p = Profile.objects.get(user__email=self.channel.value)
|
||||||
|
sort = p.sort
|
||||||
|
except Profile.DoesNotExist:
|
||||||
|
# Default sort order is by check's creation time
|
||||||
|
sort = "created"
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"check": check,
|
"check": check,
|
||||||
"checks": self.checks(),
|
"checks": self.checks(),
|
||||||
|
"sort": sort,
|
||||||
"now": timezone.now(),
|
"now": timezone.now(),
|
||||||
"unsub_link": self.channel.get_unsub_link()
|
"unsub_link": self.channel.get_unsub_link()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
@ -31,3 +33,28 @@ def mangle_link(s):
|
|||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def site_root():
|
def site_root():
|
||||||
return settings.SITE_ROOT
|
return settings.SITE_ROOT
|
||||||
|
|
||||||
|
|
||||||
|
def naturalize_int_match(match):
|
||||||
|
return '%08d' % (int(match.group(0)),)
|
||||||
|
|
||||||
|
|
||||||
|
def natural_name_key(check):
|
||||||
|
s = check.name.lower().strip()
|
||||||
|
return re.sub(r'\d+', naturalize_int_match, s)
|
||||||
|
|
||||||
|
|
||||||
|
def last_ping_key(check):
|
||||||
|
return check.last_ping.isoformat() if check.last_ping else "9999"
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def sortchecks(checks, key):
|
||||||
|
if key == "created":
|
||||||
|
checks.sort(key=lambda check: check.created)
|
||||||
|
elif key.endswith("name"):
|
||||||
|
checks.sort(key=natural_name_key, reverse=key.startswith("-"))
|
||||||
|
elif key.endswith("last_ping"):
|
||||||
|
checks.sort(key=last_ping_key, reverse=key.startswith("-"))
|
||||||
|
|
||||||
|
return checks
|
||||||
|
|||||||
@ -40,9 +40,7 @@ def my_checks(request):
|
|||||||
request.profile.sort = request.GET["sort"]
|
request.profile.sort = request.GET["sort"]
|
||||||
request.profile.save()
|
request.profile.save()
|
||||||
|
|
||||||
q = Check.objects.filter(user=request.team.user)
|
checks = list(Check.objects.filter(user=request.team.user))
|
||||||
q = q.order_by(request.profile.sort)
|
|
||||||
checks = list(q)
|
|
||||||
|
|
||||||
tags, down_tags, grace_tags = set(), set(), set()
|
tags, down_tags, grace_tags = set(), set(), set()
|
||||||
for check in checks:
|
for check in checks:
|
||||||
|
|||||||
@ -52,7 +52,8 @@ table.table tr > th.th-name {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#checks-table > tbody > tr > th.th-period, #checks-table > tbody > tr > th.th-last-ping {
|
#checks-table > tbody > tr > th.th-period,
|
||||||
|
#checks-table > tbody > tr > th.th-last-ping {
|
||||||
padding-left: 15px;
|
padding-left: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +81,11 @@ table.table tr > th.th-name {
|
|||||||
padding: 6px;
|
padding: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#checks-table .last-ping-never {
|
||||||
|
padding: 7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#checks-table tr:hover .last-ping {
|
#checks-table tr:hover .last-ping {
|
||||||
border: 1px dotted #AAA;
|
border: 1px dotted #AAA;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ The check <strong>{{ check.name_then_code }}</strong>
|
|||||||
has gone <strong>{{ check.status|upper }}</strong>.
|
has gone <strong>{{ check.status|upper }}</strong>.
|
||||||
<br /><br />
|
<br /><br />
|
||||||
|
|
||||||
Here is a summary of all your checks:
|
Here is a summary of your checks:
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
{% include "emails/summary-html.html" %}
|
{% include "emails/summary-html.html" %}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="mobile-hide" style="padding: 32px 8px 8px 8px; margin: 0; font-size: 12px; color: #9BA2AB; font-family: Helvetica, Arial, sans-serif;">Last Ping</td>
|
<td class="mobile-hide" style="padding: 32px 8px 8px 8px; margin: 0; font-size: 12px; color: #9BA2AB; font-family: Helvetica, Arial, sans-serif;">Last Ping</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% for check in group.list %}
|
{% for check in group.list|sortchecks:sort %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="border-top: 1px solid #EDEFF2; padding: 16px 8px;">
|
<td style="border-top: 1px solid #EDEFF2; padding: 16px 8px;">
|
||||||
<table cellpadding="0" cellspacing="0">
|
<table cellpadding="0" cellspacing="0">
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
</th>
|
</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for check in checks %}
|
{% for check in checks|sortchecks:sort %}
|
||||||
<tr class="checks-row">
|
<tr class="checks-row">
|
||||||
<td class="indicator-cell">
|
<td class="indicator-cell">
|
||||||
{% if check.get_status == "new" %}
|
{% if check.get_status == "new" %}
|
||||||
@ -94,7 +94,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
Never
|
<div class="last-ping-never">Never</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{% load hc_extras humanize %}
|
{% load hc_extras humanize %}
|
||||||
|
|
||||||
<ul id="checks-list" class="visible-xs">
|
<ul id="checks-list" class="visible-xs">
|
||||||
{% for check in checks %}
|
{% for check in checks|sortchecks:sort %}
|
||||||
<li>
|
<li>
|
||||||
<h2>
|
<h2>
|
||||||
<span class="{% if not check.name %}unnamed{% endif %}">
|
<span class="{% if not check.name %}unnamed{% endif %}">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user