From 2abec6ff6a00e95493e5529f2d5df5c644521402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Sat, 11 Jul 2015 14:19:02 +0300 Subject: [PATCH] Nicer emails --- hc/api/models.py | 5 +++- hc/front/urls.py | 1 + hc/front/views.py | 26 ++++++++++++++++- templates/emails/alert/body.html | 50 +++++++++++++++++++++++++++----- templates/emails/login/body.html | 7 ++++- 5 files changed, 79 insertions(+), 10 deletions(-) diff --git a/hc/api/models.py b/hc/api/models.py index 679aa16b..8c816864 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -4,6 +4,7 @@ import uuid from django.conf import settings from django.contrib.auth.models import User from django.db import models +from django.utils import timezone from hc.lib.emails import send @@ -40,7 +41,9 @@ class Check(models.Model): ctx = { "timeout_choices": TIMEOUT_CHOICES, "check": self, - "checks": self.user.check_set.order_by("created") + "checks": self.user.check_set.order_by("created"), + "now": timezone.now() + } if self.status in ("up", "down"): diff --git a/hc/front/urls.py b/hc/front/urls.py index 4d029112..eeca64ff 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -7,6 +7,7 @@ urlpatterns = [ url(r'^checks/add/$', views.add_check, name="hc-add-check"), url(r'^checks/([\w-]+)/name/$', views.update_name, name="hc-update-name"), url(r'^checks/([\w-]+)/timeout/$', views.update_timeout, name="hc-update-timeout"), + url(r'^checks/([\w-]+)/email/$', views.email_preview), url(r'^pricing/$', views.pricing, name="hc-pricing"), url(r'^docs/$', views.docs, name="hc-docs"), url(r'^about/$', views.about, name="hc-about"), diff --git a/hc/front/views.py b/hc/front/views.py index 97334f24..1e7b0916 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -41,7 +41,7 @@ def _my_checks(request): ctx = { "checks": checks, - "now": timezone.now, + "now": timezone.now(), "timeout_choices": TIMEOUT_CHOICES } @@ -104,3 +104,27 @@ def update_timeout(request, code): check.save() return redirect("hc-index") + + +@login_required +def email_preview(request, code): + """ A debug view to see how email will look. + + Will keep it around until I'm happy with email stying. + + """ + + check = Check.objects.get(code=code) + if check.user != request.user: + return HttpResponseForbidden() + + from hc.api.models import TIMEOUT_CHOICES + ctx = { + "check": check, + "checks": check.user.check_set.all(), + "timeout_choices": TIMEOUT_CHOICES, + "now": timezone.now() + + } + + return render(request, "emails/alert/body.html", ctx) diff --git a/templates/emails/alert/body.html b/templates/emails/alert/body.html index 0908ec12..680c36f8 100644 --- a/templates/emails/alert/body.html +++ b/templates/emails/alert/body.html @@ -1,8 +1,36 @@ {% load humanize %} + +

Hello,

-

This is a notification sent by healthchecks.io

-

The check "{{ check.name }}" has gone {{ check.status }}.

+

This is a notification sent by healthchecks.io.

+

The check "{{ check.name|default:check.code }}" has gone {{ check.status }}.

Here is a summary of all your checks:

@@ -17,15 +45,19 @@
{% if check.status == "new" %} - + NEW {% elif now < check.alert_after %} - + UP {% else %} - + DOWN {% endif %} - {{ check.name }} + {% if check.name %} + {{ check.name }} + {% else %} + unnamed + {% endif %} {{ check.url }} @@ -48,4 +80,8 @@ {% endfor %}
- +

+ --
+ Regards,
+ healthchecks.io +

diff --git a/templates/emails/login/body.html b/templates/emails/login/body.html index eb14b04d..61467800 100644 --- a/templates/emails/login/body.html +++ b/templates/emails/login/body.html @@ -1,5 +1,10 @@ -

Hello from healthchecks.io!

+

Hello,

Here's a link to log yourself in:

{{ login_link }}

+

+ --
+ Regards,
+ healthchecks.io +