From f4b2fa9bdc3979ddf2ab0ef65f09ac809b3f316d Mon Sep 17 00:00:00 2001 From: Alex Manning Date: Fri, 25 Oct 2024 17:12:29 +0100 Subject: [PATCH] Create a dashboard of pending requests. --- jasmin_services/admin/__init__.py | 3 +- jasmin_services/admin/dashboard.py | 34 +++++++++++++++++++ .../admin/jasmin_services/dashboard.html | 31 +++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 jasmin_services/admin/dashboard.py create mode 100644 jasmin_services/templates/admin/jasmin_services/dashboard.html diff --git a/jasmin_services/admin/__init__.py b/jasmin_services/admin/__init__.py index 204ed24..b5275f1 100644 --- a/jasmin_services/admin/__init__.py +++ b/jasmin_services/admin/__init__.py @@ -40,10 +40,11 @@ # Load the admin for behaviours which are turned on. from . import behaviour # unimport:skip -from . import filters, grant +from . import dashboard, filters, grant # Register admins from submodules. admin.site.register(Grant, grant.GrantAdmin) +admin.site.register_view("jasmin_services/dashboard/", view=dashboard.AdminDashboardView) class GroupAdmin(admin.ModelAdmin): diff --git a/jasmin_services/admin/dashboard.py b/jasmin_services/admin/dashboard.py new file mode 100644 index 0000000..957c406 --- /dev/null +++ b/jasmin_services/admin/dashboard.py @@ -0,0 +1,34 @@ +import django.db.models +import django.views.generic + +from .. import models as js_models + + +class AdminDashboardView(django.views.generic.base.TemplateView): + template_name = "admin/jasmin_services/dashboard.html" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + roles_with_pending_requests = ( + js_models.Role.objects.all() + .annotate( + num_pending=django.db.models.Count( + "access", + filter=django.db.models.Q( + access__request__state=js_models.RequestState.PENDING + ), + ) + ) + .filter(num_pending__gt=0) + ) + ceda_managed_pending = roles_with_pending_requests # .filter(service__ceda_managed=True) # TODO: Reinstate this check. + longer_than_a_week_pending = roles_with_pending_requests # TODO: write this check. + no_approver_pending = roles_with_pending_requests # TODO: write this check. + + extra_context = { + "ceda_managed_pending": ceda_managed_pending, + "longer_than_a_week_pending": longer_than_a_week_pending, + "no_approver_pending": no_approver_pending, + } + return context | extra_context diff --git a/jasmin_services/templates/admin/jasmin_services/dashboard.html b/jasmin_services/templates/admin/jasmin_services/dashboard.html new file mode 100644 index 0000000..2b84c70 --- /dev/null +++ b/jasmin_services/templates/admin/jasmin_services/dashboard.html @@ -0,0 +1,31 @@ +{% extends "admin/base_site.html" %} +{% load i18n static %} + +{% block extrastyle %}{{ block.super }}{% endblock %} + +{% block coltype %}colMS{% endblock %} + +{% block bodyclass %}{{ block.super }} dashboard{% endblock %} + +{% block nav-breadcrumbs %}{% endblock %} + +{% block nav-sidebar %}{% endblock %} + +{% block content %} + + + + + + {% for role in ceda_managed_pending %} + + + + + + {% endfor %} +
ServiceRoleNumber of Pending Requests
{{role.service.category.name}}/{{ role.service.name }}{{ role.name }}{{ role.num_pending }}
+{% endblock %} + +{% block sidebar %} +{% endblock %}