Browse Source

Update channels.html to use Channel.last_notify

Channel.last_notify is the datetime of the most recent
notification sent via the channel. Channel.last_error is
the error message (blank if the delivery was successful).

In the integrations list, "Last Notification" column,
use these fields instead of looking up the most recent
Notification object. This saves some db queries,
and also fixes a subtle issue: if prunenotifications
cleans up all notifications for a given channel, the
"Last Notification" column would display "Never", which
would not be correct – not any more.
master
Pēteris Caune 3 years ago
parent
commit
bcc7009437
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 6 additions and 11 deletions
  1. +1
    -1
      hc/api/management/commands/backfillchannels.py
  2. +0
    -3
      hc/api/models.py
  3. +5
    -7
      templates/front/channels.html

+ 1
- 1
hc/api/management/commands/backfillchannels.py View File

@ -13,7 +13,7 @@ class Command(BaseCommand):
q = Channel.objects.filter(id=channel.id)
try:
n = channel.latest_notification()
n = Notification.objects.filter(channel=channel).latest()
q.update(last_notify=n.created, last_error=n.error)
total += 1
except Notification.DoesNotExist:


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

@ -550,9 +550,6 @@ class Channel(models.Model):
def icon_path(self):
return "img/integrations/%s.png" % self.kind
def latest_notification(self):
return Notification.objects.filter(channel=self).latest()
@property
def json(self):
return json.loads(self.value)


+ 5
- 7
templates/front/channels.html View File

@ -26,7 +26,6 @@
<th></th>
</tr>
{% for ch in channels %}
{% with n=ch.latest_notification %}
<tr class="channel-row kind-{{ ch.kind }}">
<td class="icon-cell">
<img src="{% static ch.icon_path %}" alt="{{ ch.get_kind_display }}" />
@ -125,13 +124,13 @@
{% endif %}
</td>
<td>
{% if n %}
{% if n.error %}
<span class="text-danger" data-toggle="tooltip" title="{{ n.error }}">
<strong>Failed</strong>, {{ n.created|naturaltime }}
{% if ch.last_notify %}
{% if ch.last_error %}
<span class="text-danger" data-toggle="tooltip" title="{{ ch.last_error }}">
<strong>Failed</strong>, {{ ch.last_notify|naturaltime }}
</span>
{% else %}
Delivered, {{ n.created|naturaltime }}
Delivered, {{ ch.last_notify|naturaltime }}
{% endif %}
{% else %}
Never
@ -168,7 +167,6 @@
{% endif %}
</td>
</tr>
{% endwith %}
{% endfor %}
</table>
{% else %}


Loading…
Cancel
Save