Skip to content

Commit

Permalink
Merge pull request #32 from andela/ft-periodic-reports-153728007
Browse files Browse the repository at this point in the history
Add reports dashboard
  • Loading branch information
kevinsamoei committed Feb 6, 2018
2 parents 0b4e6e4 + edc624d commit c69be88
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions hc/front/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
urlpatterns = [
url(r'^$', views.index, name="hc-index"),
url(r'^checks/$', views.my_checks, name="hc-checks"),
url(r'^reports/$', views.my_reports, name="hc-reports"),
url(r'^checks/team$', views.team_checks, name="hc-team-checks"),
url(r'^checks/add/$', views.add_check, name="hc-add-check"),
url(r'^checks/([\w-]+)/', include(check_urls)),
Expand Down
35 changes: 35 additions & 0 deletions hc/front/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.db.models import Count
from hc.accounts.models import Profile
from django.http import Http404, HttpResponseBadRequest, HttpResponseForbidden
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
Expand Down Expand Up @@ -96,6 +97,40 @@ def my_checks(request):

return render(request, "front/my_checks.html", ctx)

@login_required
def my_reports(request):
profile = request.user.profile
q = Check.objects.filter(user=request.team.user)
q = q.filter(last_ping__isnull=False)
checks = list(q)
counter = Counter()
down_tags, grace_tags = set(), set()
for check in checks:
status = check.get_status()
for tag in check.tags_list():
if tag == "":
continue

counter[tag] += 1

if status == "down":
down_tags.add(tag)
elif check.in_grace_period():
grace_tags.add(tag)

ctx = {
"page": "reports",
"checks": checks,
"now": timezone.now(),
"tags": counter.most_common(),
"down_tags": down_tags,
"grace_tags": grace_tags,
"reports_allowed": profile.reports_allowed,
"ping_endpoint": settings.PING_ENDPOINT
}

return render(request, "front/reports.html", ctx)


def _welcome_check(request):
check = None
Expand Down
3 changes: 3 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
<li {% if page == 'channels' %} class="active" {% endif %}>
<a href="{% url 'hc-channels' %}">Integrations</a>
</li>
<li {% if page == 'reports' %} class="active" {% endif %}>
<a href="{% url 'hc-reports' %}">Reports</a>
</li>

{% endif %}

Expand Down

0 comments on commit c69be88

Please sign in to comment.