paperwork: Add Certifiers and Certification Count reports

This commit is contained in:
Adam Goldsmith 2024-02-16 11:35:12 -05:00
parent 6c5e55507e
commit f9fdd7d549
5 changed files with 114 additions and 1 deletions

View File

@ -29,6 +29,16 @@ class PaperworkDashboardFragment(dashboard.LinksCardDashboardFragment):
reverse("paperwork:access-verification-report"), reverse("paperwork:access-verification-report"),
permission="paperwork.view_certification", 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) member = Member.from_user(self.request.user)

View File

@ -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 %}

View File

@ -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 %}

View File

@ -40,4 +40,14 @@ urlpatterns = [
views.AccessVerificationReport.as_view(), views.AccessVerificationReport.as_view(),
name="access-verification-report", name="access-verification-report",
), ),
path(
"certifiers",
views.CertifiersReport.as_view(),
name="certifiers-report",
),
path(
"certification-count",
views.CertificationCountReport.as_view(),
name="certification-count-report",
),
] ]

View File

@ -3,7 +3,7 @@ from django.contrib import staticfiles
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db import models 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.db.models.functions import Concat
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotFound from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotFound
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
@ -324,3 +324,72 @@ class AccessVerificationReport(
) )
) )
return qs 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")
)