From f9fdd7d549d8d054f2a7780ddcb94665a0464fe3 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 16 Feb 2024 11:35:12 -0500 Subject: [PATCH] paperwork: Add Certifiers and Certification Count reports --- paperwork/dashboard.py | 10 +++ .../certification_count_report.dj.html | 12 ++++ .../paperwork/certifiers_report.dj.html | 12 ++++ paperwork/urls.py | 10 +++ paperwork/views.py | 71 ++++++++++++++++++- 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 paperwork/templates/paperwork/certification_count_report.dj.html create mode 100644 paperwork/templates/paperwork/certifiers_report.dj.html diff --git a/paperwork/dashboard.py b/paperwork/dashboard.py index f3e4dab..de9d82b 100644 --- a/paperwork/dashboard.py +++ b/paperwork/dashboard.py @@ -29,6 +29,16 @@ class PaperworkDashboardFragment(dashboard.LinksCardDashboardFragment): reverse("paperwork:access-verification-report"), permission="paperwork.view_certification", ), + Link( + "Certifiers", + reverse("paperwork:certifiers-report"), + permission="paperwork.view_certification", + ), + Link( + "Certification Count", + reverse("paperwork:certification-count-report"), + permission="paperwork.view_certification", + ), ] member = Member.from_user(self.request.user) diff --git a/paperwork/templates/paperwork/certification_count_report.dj.html b/paperwork/templates/paperwork/certification_count_report.dj.html new file mode 100644 index 0000000..b3441a7 --- /dev/null +++ b/paperwork/templates/paperwork/certification_count_report.dj.html @@ -0,0 +1,12 @@ +{% extends "base.dj.html" %} + +{% load render_table from django_tables2 %} + +{% block title %}Certification Count Report{% endblock %} +{% block admin_link %} + {% url 'admin:paperwork_certification_changelist' %} +{% endblock %} +{% block content %} + {% include "cmsmanage/components/download_table.dj.html" %} + {% render_table table %} +{% endblock %} diff --git a/paperwork/templates/paperwork/certifiers_report.dj.html b/paperwork/templates/paperwork/certifiers_report.dj.html new file mode 100644 index 0000000..2e2f269 --- /dev/null +++ b/paperwork/templates/paperwork/certifiers_report.dj.html @@ -0,0 +1,12 @@ +{% extends "base.dj.html" %} + +{% load render_table from django_tables2 %} + +{% block title %}Certifiers Report{% endblock %} +{% block admin_link %} + {% url 'admin:paperwork_certification_changelist' %} +{% endblock %} +{% block content %} + {% include "cmsmanage/components/download_table.dj.html" %} + {% render_table table %} +{% endblock %} diff --git a/paperwork/urls.py b/paperwork/urls.py index de14918..0d2f308 100644 --- a/paperwork/urls.py +++ b/paperwork/urls.py @@ -40,4 +40,14 @@ urlpatterns = [ views.AccessVerificationReport.as_view(), name="access-verification-report", ), + path( + "certifiers", + views.CertifiersReport.as_view(), + name="certifiers-report", + ), + path( + "certification-count", + views.CertificationCountReport.as_view(), + name="certification-count-report", + ), ] diff --git a/paperwork/views.py b/paperwork/views.py index 2562774..69fbc95 100644 --- a/paperwork/views.py +++ b/paperwork/views.py @@ -3,7 +3,7 @@ from django.contrib import staticfiles from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import PermissionRequiredMixin from django.db import models -from django.db.models import Case, Q, Value, When +from django.db.models import Case, Count, Max, Q, Value, When from django.db.models.functions import Concat from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotFound from django.shortcuts import get_object_or_404, render @@ -324,3 +324,72 @@ class AccessVerificationReport( ) ) return qs + + +class CertifiersTable(tables.Table): + certified_by = tables.Column() + certification_version__definition__name = tables.Column("Certification") + certification_version__definition__department__name = tables.Column("Department") + number_issued_on_this_tool = tables.Column() + last_issued_certification_date = tables.Column() + + +class CertifiersReport( + ExportMixin, + SingleTableMixin, + PermissionRequiredMixin, + ListView, +): + model = Certification + permission_required = "paperwork.view_certification" + template_name = "paperwork/certifiers_report.dj.html" + table_class = CertifiersTable + export_formats = ("csv", "xlsx", "ods") + + def get_queryset(self): + qs = super().get_queryset() + return ( + qs.values( + "certification_version__definition__department__name", + "certification_version__definition__name", + "certified_by", + ) + .annotate( + number_issued_on_this_tool=Count("*"), + last_issued_certification_date=Max("date"), + ) + .order_by( + "certification_version__definition__name", + "last_issued_certification_date", + ) + ) + + +class CertificationCountTable(tables.Table): + certification_version__definition__name = tables.Column("Certification") + certification_version__definition__department__name = tables.Column("Department") + total_issued = tables.Column() + + +class CertificationCountReport( + ExportMixin, + SingleTableMixin, + PermissionRequiredMixin, + ListView, +): + model = Certification + permission_required = "paperwork.view_certification" + template_name = "paperwork/certification_count_report.dj.html" + table_class = CertificationCountTable + export_formats = ("csv", "xlsx", "ods") + + def get_queryset(self): + qs = super().get_queryset() + return ( + qs.values( + "certification_version__definition__name", + "certification_version__definition__department__name", + ) + .annotate(total_issued=Count("*")) + .order_by("certification_version__definition__name") + )