Browse Source

Improve project sorting in the "My Projects" page

Primary sort key: projects with overall_status=down go first
Secondary sort key: project's name
pull/504/head
Pēteris Caune 4 years ago
parent
commit
738a648407
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
4 changed files with 20 additions and 9 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +2
    -0
      hc/accounts/models.py
  3. +12
    -2
      hc/front/views.py
  4. +5
    -7
      templates/front/projects.html

+ 1
- 0
CHANGELOG.md View File

@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- Improve HTML email display in the "Ping Details" dialog
- Add a link to check's details page in Slack notifications
- Replace details_url with cloaked_url in email and chat notifications
- In the "My Projects" page, show projects with failing checks first
## Bug Fixes
- Fix downtime summary to handle months when the check didn't exist yet (#472)


+ 2
- 0
hc/accounts/models.py View File

@ -1,4 +1,5 @@
from datetime import timedelta
from functools import cached_property
from secrets import token_urlsafe
from urllib.parse import quote, urlencode
import uuid
@ -342,6 +343,7 @@ class Project(models.Model):
for profile in q:
profile.update_next_nag_date()
@cached_property
def overall_status(self):
status = "up"
for check in self.check_set.all():


+ 12
- 2
hc/front/views.py View File

@ -13,7 +13,7 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.core import signing
from django.core.exceptions import PermissionDenied
from django.db.models import Count
from django.db.models import Count, F
from django.http import (
Http404,
HttpResponse,
@ -275,7 +275,17 @@ def switch_channel(request, code, channel_code):
def index(request):
if request.user.is_authenticated:
projects = list(request.profile.projects())
project_ids = request.profile.projects().values("id")
q = Project.objects.filter(id__in=project_ids)
q = q.annotate(n_checks=Count("check", distinct=True))
q = q.annotate(n_channels=Count("channel", distinct=True))
q = q.annotate(owner_email=F("owner__email"))
projects = list(q)
# Primary sort key: projects with overall_status=down go first
# Secondary sort key: project's name
projects.sort(key=lambda p: (p.overall_status != "down", p.name))
ctx = {
"page": "projects",


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

@ -21,16 +21,14 @@
<h4>{{ project }}</h4>
<div>
{% with project.check_set.count as n %}
{{ n }} check{{ n|pluralize }},
{% endwith %}
{{ project.n_checks }}
check{{ project.n_checks|pluralize }},
{% with project.channel_set.count as n %}
{{ n }} integration{{ n|pluralize }}
{% endwith %}
{{ project.n_channels }}
integration{{ project.n_channels|pluralize }}
</div>
<div class="text-muted">
{{ project.owner.email }}
{{ project.owner_email }}
</div>
</div>


Loading…
Cancel
Save