forked from GithubBackups/healthchecks
Show "grace" status in the "List of Projects" page. Fix the query for badges in top nav.
This commit is contained in:
parent
62310a5181
commit
b0f4bd3fce
@ -122,12 +122,16 @@ class Profile(models.Model):
|
||||
def annotated_projects(self):
|
||||
""" Return all projects, annotated with 'n_down'. """
|
||||
|
||||
is_owner = Q(owner=self.user)
|
||||
is_member = Q(member__user=self.user)
|
||||
q = Project.objects.filter(is_owner | is_member)
|
||||
# Subquery for getting project ids
|
||||
project_ids = self.projects().values("id")
|
||||
|
||||
# Main query with the n_down annotation.
|
||||
# Must use the subquery, otherwise ORM gets confused by
|
||||
# joins and group by's
|
||||
q = Project.objects.filter(id__in=project_ids)
|
||||
n_down = Count("check", filter=Q(check__status="down"))
|
||||
q = q.annotate(n_down=n_down)
|
||||
return q.distinct().order_by("name")
|
||||
return q.order_by("name")
|
||||
|
||||
def checks_from_all_projects(self):
|
||||
""" Return a queryset of checks from projects we have access to. """
|
||||
@ -256,6 +260,18 @@ class Project(models.Model):
|
||||
|
||||
q.update(next_nag_date=timezone.now() + models.F("nag_period"))
|
||||
|
||||
def overall_status(self):
|
||||
status = "up"
|
||||
for check in self.check_set.all():
|
||||
check_status = check.get_status(with_started=False)
|
||||
if status == "up" and check_status == "grace":
|
||||
status = "grace"
|
||||
|
||||
if check_status == "down":
|
||||
status = "down"
|
||||
break
|
||||
return status
|
||||
|
||||
|
||||
class Member(models.Model):
|
||||
user = models.ForeignKey(User, models.CASCADE, related_name="memberships")
|
||||
|
@ -195,7 +195,7 @@ def switch_channel(request, code, channel_code):
|
||||
|
||||
def index(request):
|
||||
if request.user.is_authenticated:
|
||||
projects = list(request.profile.annotated_projects())
|
||||
projects = list(request.profile.projects())
|
||||
|
||||
if len(projects) == 1:
|
||||
return redirect("hc-checks", projects[0].code)
|
||||
|
@ -23,11 +23,7 @@
|
||||
<a href="{% url 'hc-checks' project.code %}">
|
||||
<div class="col-sm-6 col-md-4">
|
||||
<div class="panel project {% if project == request.profile.current_project %}selected{% endif %}">
|
||||
{% if project.n_down %}
|
||||
<div class="status icon-down"></div>
|
||||
{% else %}
|
||||
<div class="status icon-up"></div>
|
||||
{% endif %}
|
||||
<div class="status icon-{{ project.overall_status }}"></div>
|
||||
|
||||
<h4>{{ project }}</h4>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user