Browse Source

Display last notification in Integrations page.

pull/40/head
Pēteris Caune 9 years ago
parent
commit
2c04a42a57
4 changed files with 27 additions and 1 deletions
  1. +6
    -0
      hc/api/models.py
  2. +3
    -0
      hc/front/views.py
  3. +1
    -0
      static/js/channels.js
  4. +17
    -1
      templates/front/channels.html

+ 6
- 0
hc/api/models.py View File

@ -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)


+ 3
- 0
hc/front/views.py View File

@ -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 = {


+ 1
- 0
static/js/channels.js View File

@ -46,5 +46,6 @@ $(function() {
return false;
});
$('[data-toggle="tooltip"]').tooltip();
});

+ 17
- 1
templates/front/channels.html View File

@ -13,6 +13,7 @@
<th>Type</th>
<th>Value</th>
<th>Assigned Checks</th>
<th>Last Notification</th>
<th></th>
</tr>
{% for ch in channels %}
@ -47,9 +48,24 @@
<a
class="edit-checks"
href="{% url 'hc-channel-checks' ch.code %}">
{{ ch.checks.count }} of {{ num_checks }}
{{ ch.n_checks }} of {{ num_checks }}
</a>
</td>
<td>
{% with n=ch.latest_notification %}
{% if n %}
{% if n.error %}
<span class="text-danger" data-toggle="tooltip" title="{{ n.error }}">
<strong>Failed</strong>, {{ n.created|naturaltime }}
</span>
{% else %}
Delivered, {{ n.created|naturaltime }}
{% endif %}
{% else %}
Never
{% endif %}
{% endwith %}
</td>
<td>
<button
data-name="{{ ch.value }}"


Loading…
Cancel
Save