Browse Source

Show "grace" status in the "List of Projects" page. Fix the query for badges in top nav.

pull/194/head
Pēteris Caune 6 years ago
parent
commit
b0f4bd3fce
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 22 additions and 10 deletions
  1. +20
    -4
      hc/accounts/models.py
  2. +1
    -1
      hc/front/views.py
  3. +1
    -5
      templates/front/projects.html

+ 20
- 4
hc/accounts/models.py View File

@ -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")


+ 1
- 1
hc/front/views.py View File

@ -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)


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

@ -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…
Cancel
Save