From 78e42dd70696a58df6ed0c905fb9fd9a9e65b970 Mon Sep 17 00:00:00 2001 From: Chris Arridge Date: Mon, 4 Nov 2024 18:08:30 +0000 Subject: [PATCH] refactor: Added registration agencies page Added the registration agencies page. Code for the view was taken from make_html.py. --- .../templates/registration_agencies.html | 8 +++--- dashboard/ui/urls.py | 7 +++-- dashboard/ui/views.py | 27 +++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/dashboard/templates/registration_agencies.html b/dashboard/templates/registration_agencies.html index 8f3fe14ee..67d0ee214 100644 --- a/dashboard/templates/registration_agencies.html +++ b/dashboard/templates/registration_agencies.html @@ -1,5 +1,5 @@ {% extends 'base.html' %} -{% import '_partials/boxes.html' as boxes %} +{% import '_partials/boxes.html' as boxes with context %} {% block content %}
@@ -19,7 +19,7 @@

Publishers -{% for registration_agency, count in sorted(registration_agencies.items()) %} +{% for registration_agency, count in func.sorted(registration_agencies.items()) %} {{ registration_agency }} {{ count }} @@ -51,8 +51,8 @@

{% for publisher, count in publishers.items() %} {{ orgid|replace(' ', ' ') }} - {{ publisher }} - {{ publisher_name[publisher] }} + {{ publisher }} + {{ publisher_name[publisher] }} {{ count }} {% endfor %} diff --git a/dashboard/ui/urls.py b/dashboard/ui/urls.py index 0f73ca9ca..f10c68bb8 100644 --- a/dashboard/ui/urls.py +++ b/dashboard/ui/urls.py @@ -16,7 +16,7 @@ """ from django.contrib import admin from django.urls import path -# from django.shortcuts import redirect +from django.views.generic.base import RedirectView import ui.views @@ -73,6 +73,10 @@ path('publishing-statistics/summary-statistics', ui.views.pubstats_summarystats, name="dash-publishingstats-summarystats"), path('publishing-statistics/humanitarian-reporting', ui.views.pubstats_humanitarian, name="dash-publishingstats-humanitarian"), + # Registration agencies. + path('registration-agencies', ui.views.registration_agencies, name="dash-registrationagencies"), + path("registration_agencies.html", RedirectView.as_view(pattern_name="dash-registrationagencies", permanent=True)) + # Redirects to support any users with bookmarks to pages on the old Dashboard. # path('timeliness.html', redirect("dash-publishingstats-timeliness")), # path('index.html', redirect("dash-index")), @@ -80,4 +84,3 @@ # path('exploring_data.html', redirect("dash-exploringdata")) ] -# Unsure where "rulesets" and "registration_agencies" should belong - can't find the route to these in make_html.py diff --git a/dashboard/ui/views.py b/dashboard/ui/views.py index 0e948642d..dc2e81b26 100644 --- a/dashboard/ui/views.py +++ b/dashboard/ui/views.py @@ -87,6 +87,12 @@ def _get_licenses_for_publisher(publisher_name): for package in ckan[publisher_name].values()]) +def _registration_agency(orgid): + for code in codelist_sets['2']['OrganisationRegistrationAgency']: + if orgid.startswith(code): + return code + + def dictinvert(d): inv = collections.defaultdict(list) for k, v in d.items(): @@ -478,3 +484,24 @@ def pubstats_humanitarian(request): context = _make_context("humanitarian") context["humanitarian"] = humanitarian return HttpResponse(template.render(context, request)) + + +# +# Registration agencies page. +# +def registration_agencies(request): + template = loader.get_template("registration_agencies.html") + + context = _make_context("registration_agencies") + context["registration_agencies"] = collections.defaultdict(int) + context["registration_agencies_publishers"] = collections.defaultdict(list) + context["nonmatching"] = [] + for orgid, publishers in current_stats['inverted_publisher']['reporting_orgs'].items(): + reg_ag = _registration_agency(orgid) + if reg_ag: + context["registration_agencies"][reg_ag] += 1 + context["registration_agencies_publishers"][reg_ag] += list(publishers) + else: + context["nonmatching"].append((orgid, publishers)) + + return HttpResponse(template.render(context, request))