Browse Source

"My Checks" page: show the number of failed checks in the page title.

pull/178/head
Pēteris Caune 7 years ago
parent
commit
9ae4235c9b
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
6 changed files with 29 additions and 9 deletions
  1. +8
    -0
      hc/front/templatetags/hc_extras.py
  2. +13
    -5
      hc/front/views.py
  3. +5
    -0
      static/js/checks.js
  4. +1
    -2
      templates/front/my_checks.html
  5. +1
    -1
      templates/front/snippets/python_requests_fail.html
  6. +1
    -1
      templates/front/snippets/python_requests_fail.txt

+ 8
- 0
hc/front/templatetags/hc_extras.py View File

@ -73,3 +73,11 @@ def sortchecks(checks, key):
@register.filter
def trunc(s):
return s[:150]
@register.filter
def num_down_title(num_down):
if num_down:
return "%d down – %s" % (num_down, settings.SITE_NAME)
else:
return settings.SITE_NAME

+ 13
- 5
hc/front/views.py View File

@ -24,7 +24,7 @@ from hc.front.forms import (AddWebhookForm, NameTagsForm,
TimeoutForm, AddUrlForm, AddEmailForm,
AddOpsGenieForm, CronForm, AddSmsForm)
from hc.front.schemas import telegram_callback
from hc.front.templatetags.hc_extras import sortchecks
from hc.front.templatetags.hc_extras import num_down_title, sortchecks
from hc.lib import jsonschema
from pytz import all_timezones
from pytz.exceptions import UnknownTimeZoneError
@ -35,9 +35,10 @@ VALID_SORT_VALUES = ("name", "-name", "last_ping", "-last_ping", "created")
def _tags_statuses(checks):
tags, down, grace = {}, {}, {}
tags, down, grace, num_down = {}, {}, {}, 0
for check in checks:
if check.get_status() == "down":
num_down += 1
for tag in check.tags_list():
down[tag] = "down"
elif check.in_grace_period():
@ -49,7 +50,7 @@ def _tags_statuses(checks):
tags.update(grace)
tags.update(down)
return tags
return tags, num_down
@login_required
@ -61,12 +62,14 @@ def my_checks(request):
checks = list(Check.objects.filter(user=request.team.user))
sortchecks(checks, request.profile.sort)
pairs = list(_tags_statuses(checks).items())
tags_statuses, num_down = _tags_statuses(checks)
pairs = list(tags_statuses.items())
pairs.sort(key=lambda pair: pair[0].lower())
ctx = {
"page": "checks",
"checks": checks,
"num_down": num_down,
"now": timezone.now(),
"tags": pairs,
"ping_endpoint": settings.PING_ENDPOINT,
@ -93,7 +96,12 @@ def status(request):
"last_ping": render_to_string("front/last_ping_cell.html", ctx)
})
return JsonResponse({"details": details, "tags": _tags_statuses(checks)})
tags_statuses, num_down = _tags_statuses(checks)
return JsonResponse({
"details": details,
"tags": tags_statuses,
"title": num_down_title(num_down)
})
def _welcome_check(request):


+ 5
- 0
static/js/checks.js View File

@ -297,6 +297,11 @@ $(function () {
this.setAttribute("class", "btn btn-xs " + status);
}
});
if (document.title != data.title) {
document.title = data.title;
}
}
});
}


+ 1
- 2
templates/front/my_checks.html View File

@ -1,8 +1,7 @@
{% extends "base.html" %}
{% load compress staticfiles hc_extras %}
{% block title %}My Checks - {% site_name %}{% endblock %}
{% block title %}{{ num_down|num_down_title }}{% endblock %}
{% block content %}
<div class="row">


+ 1
- 1
templates/front/snippets/python_requests_fail.html View File

@ -2,7 +2,7 @@
<span class="n">URL</span> <span class="o">=</span> <span class="s2">&quot;{{ ping_url }}&quot;</span>
<span class="k">def</span> <span class="nf">do_work</span><span class="p">():</span>
<span class="c1"># Do actual work here.</span>
<span class="c1"># Do your number crunching, backup dumping, newsletter sending work here.</span>
<span class="c1"># Return a truthy value on success.</span>
<span class="c1"># Return a falsy value or throw an exception on failure.</span>
<span class="k">return</span> <span class="bp">True</span>


+ 1
- 1
templates/front/snippets/python_requests_fail.txt View File

@ -2,7 +2,7 @@ import requests
URL = "PING_URL"
def do_work():
# Do actual work here.
# Do your number crunching, backup dumping, newsletter sending work here.
# Return a truthy value on success.
# Return a falsy value or throw an exception on failure.
return True


Loading…
Cancel
Save