Skip to content

Commit

Permalink
Create a dashboard of pending requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
amanning9 committed Oct 25, 2024
1 parent 42e0a94 commit f4b2fa9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
3 changes: 2 additions & 1 deletion jasmin_services/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
34 changes: 34 additions & 0 deletions jasmin_services/admin/dashboard.py
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions jasmin_services/templates/admin/jasmin_services/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends "admin/base_site.html" %}
{% load i18n static %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" href="{% static "admin/css/dashboard.css" %}">{% endblock %}

{% block coltype %}colMS{% endblock %}

{% block bodyclass %}{{ block.super }} dashboard{% endblock %}

{% block nav-breadcrumbs %}{% endblock %}

{% block nav-sidebar %}{% endblock %}

{% block content %}
<table>
<tr>
<th>Service</th>
<th>Role</th>
<th>Number of Pending Requests</th>
{% for role in ceda_managed_pending %}
<tr>
<td><a href="{% url 'jasmin_services:service_details' category=role.service.category.name service=role.service.name %}">{{role.service.category.name}}/{{ role.service.name }}</a></td>
<td>{{ role.name }}</td>
<td>{{ role.num_pending }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}

{% block sidebar %}
{% endblock %}

0 comments on commit f4b2fa9

Please sign in to comment.