diff --git a/hc/api/models.py b/hc/api/models.py index f4d9b37d..63dd3911 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -26,6 +26,14 @@ CHANNEL_KINDS = (("email", "Email"), ("webhook", "Webhook"), ("hipchat", "HipChat"), ("slack", "Slack"), ("pd", "PagerDuty"), ("po", "Pushover")) +PO_PRIORITIES = { + -2: "lowest", + -1: "low", + 0: "normal", + 1: "high", + 2: "emergency" +} + class Check(models.Model): @@ -195,7 +203,7 @@ class Channel(models.Model): else: title = "%s is now UP" % check.name_then_code() - user_key, priority = self.po_value + user_key, priority, _ = self.po_value payload = { "token": settings.PUSHOVER_API_TOKEN, "user": user_key, @@ -219,7 +227,7 @@ class Channel(models.Model): assert self.kind == "po" user_key, prio = self.value.split("|") prio = int(prio) - return user_key, prio + return user_key, prio, PO_PRIORITIES[prio] class Notification(models.Model): diff --git a/hc/front/views.py b/hc/front/views.py index dc3c2ad6..8edbb8f3 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -358,11 +358,8 @@ def add_pushover(request): if request.GET.get("pushover_unsubscribed", "0") == "1": # Unsubscription: delete all Pushover channels for this user - for channel in Channel.objects.filter(user=request.user, kind="po"): - channel.delete() - + Channel.objects.filter(user=request.user, kind="po").delete() return redirect("hc-channels") - else: # Subscription user_key = request.GET["pushover_user_key"] @@ -373,10 +370,10 @@ def add_pushover(request): "value": "%s|%d" % (user_key, priority), }) - else: - ctx = { - "page": "channels", - "po_retry_delay": td(seconds=settings.PUSHOVER_EMERGENCY_RETRY_DELAY), - "po_expiration": td(seconds=settings.PUSHOVER_EMERGENCY_EXPIRATION), - } - return render(request, "integrations/add_pushover.html", ctx) + # Integration Settings form + ctx = { + "page": "channels", + "po_retry_delay": td(seconds=settings.PUSHOVER_EMERGENCY_RETRY_DELAY), + "po_expiration": td(seconds=settings.PUSHOVER_EMERGENCY_EXPIRATION), + } + return render(request, "integrations/add_pushover.html", ctx) diff --git a/static/css/add_pushover.css b/static/css/add_pushover.css new file mode 100644 index 00000000..db0268e0 --- /dev/null +++ b/static/css/add_pushover.css @@ -0,0 +1,8 @@ +#add-pushover .radio { + margin-bottom: 1em; +} + +#add-pushover .help { + display: block; + color: #888; +} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 3ce911f4..de3335a8 100644 --- a/templates/base.html +++ b/templates/base.html @@ -27,6 +27,7 @@ + {% endcompress %}
diff --git a/templates/front/channels.html b/templates/front/channels.html index 12de0b30..2d76ddf5 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -29,11 +29,12 @@ {% if ch.kind == "email" %} to {% endif %} {% if ch.kind == "pd" %} API key {% endif %} - {% if ch.kind == "po" %} User key / priority {% endif %} + {% if ch.kind == "po" %} user key {% endif %} {% if ch.kind == "po" %} - {{ ch.po_value|join:" / " }} + {{ ch.po_value|first }} + ({{ ch.po_value|last }} priority) {% else %} {{ ch.value }} {% endif %} diff --git a/templates/integrations/add_pushover.html b/templates/integrations/add_pushover.html index a2bb367b..4249c8d4 100644 --- a/templates/integrations/add_pushover.html +++ b/templates/integrations/add_pushover.html @@ -16,25 +16,61 @@