forked from GithubBackups/healthchecks
Improve project sorting in the "My Projects" page
Primary sort key: projects with overall_status=down go first Secondary sort key: project's name
This commit is contained in:
parent
4587b45cab
commit
738a648407
@ -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)
|
||||
|
@ -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():
|
||||
|
@ -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",
|
||||
|
@ -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…
x
Reference in New Issue
Block a user