views.py 859 B

12345678910111213141516171819202122232425262728
  1. from django.db.models import Q
  2. from django.views.generic import DetailView
  3. from .models import Monitor, StatusPage
  4. class StatusPageDetailView(DetailView):
  5. model = StatusPage
  6. def get_queryset(self):
  7. queryset = super().get_queryset()
  8. if self.request.user.is_authenticated:
  9. queryset = queryset.filter(
  10. Q(is_public=True) | Q(organization__users=self.request.user)
  11. )
  12. else:
  13. queryset = queryset.filter(is_public=True)
  14. return queryset.filter(
  15. organization__slug=self.kwargs.get("organization")
  16. ).distinct()
  17. def get_context_data(self, **kwargs):
  18. context = super().get_context_data(**kwargs)
  19. context["monitors"] = Monitor.objects.with_check_annotations().filter(
  20. statuspage=self.object
  21. )
  22. return context