diff --git a/hc/api/models.py b/hc/api/models.py index 02fc89ce..d2c1b601 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -170,8 +170,14 @@ class Channel(models.Model): prio = int(prio) return user_key, prio, PO_PRIORITIES[prio] + def latest_notification(self): + return Notification.objects.filter(channel=self).latest() + class Notification(models.Model): + class Meta: + get_latest_by = "created" + owner = models.ForeignKey(Check) check_status = models.CharField(max_length=6) channel = models.ForeignKey(Channel) diff --git a/hc/front/views.py b/hc/front/views.py index c39b9350..1936e54f 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -5,6 +5,7 @@ from itertools import tee from django.conf import settings from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse +from django.db.models import Count from django.http import HttpResponseBadRequest, HttpResponseForbidden from django.shortcuts import get_object_or_404, redirect, render from django.utils import timezone @@ -266,6 +267,8 @@ def channels(request): return redirect("hc-channels") channels = Channel.objects.filter(user=request.user).order_by("created") + channels = channels.annotate(n_checks=Count("checks")) + num_checks = Check.objects.filter(user=request.user).count() ctx = { diff --git a/static/js/channels.js b/static/js/channels.js index fa2264a4..0417f842 100644 --- a/static/js/channels.js +++ b/static/js/channels.js @@ -46,5 +46,6 @@ $(function() { return false; }); + $('[data-toggle="tooltip"]').tooltip(); }); \ No newline at end of file diff --git a/templates/front/channels.html b/templates/front/channels.html index 10f4bd25..c22045ae 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -13,6 +13,7 @@ Type Value Assigned Checks + Last Notification {% for ch in channels %} @@ -47,9 +48,24 @@ - {{ ch.checks.count }} of {{ num_checks }} + {{ ch.n_checks }} of {{ num_checks }} + + {% with n=ch.latest_notification %} + {% if n %} + {% if n.error %} + + Failed, {{ n.created|naturaltime }} + + {% else %} + Delivered, {{ n.created|naturaltime }} + {% endif %} + {% else %} + Never + {% endif %} + {% endwith %} +