Skip to content

Commit

Permalink
refactor: Added registration agencies page
Browse files Browse the repository at this point in the history
Added the registration agencies page.  Code for the view was taken
from make_html.py.
  • Loading branch information
chrisarridge committed Nov 4, 2024
1 parent be1b889 commit 78e42dd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
8 changes: 4 additions & 4 deletions dashboard/templates/registration_agencies.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% import '_partials/boxes.html' as boxes %}
{% import '_partials/boxes.html' as boxes with context %}
{% block content %}

<div class="row">
Expand All @@ -19,7 +19,7 @@ <h3 class="panel-title">
<th>Publishers</th>
</tr></thead>
<tbody>
{% for registration_agency, count in sorted(registration_agencies.items()) %}
{% for registration_agency, count in func.sorted(registration_agencies.items()) %}
<tr>
<td>{{ registration_agency }}</td>
<td>{{ count }}</td>
Expand Down Expand Up @@ -51,8 +51,8 @@ <h3 class="panel-title">
{% for publisher, count in publishers.items() %}
<tr>
<td><code>{{ orgid|replace(' ', ' ') }}</code></td>
<td><a href="{{ url_for('publisher', publisher=publisher) }}">{{ publisher }}</a></td>
<td><a href="{{ url_for('publisher', publisher=publisher) }}">{{ publisher_name[publisher] }}</a></td>
<td><a href="{{ url('dash-headlines-publisher-detail', args=[publisher]) }}">{{ publisher }}</a></td>
<td><a href="{{ url('dash-headlines-publisher-detail', args=[publisher]) }}">{{ publisher_name[publisher] }}</a></td>
<td>{{ count }}</td>
</tr>
{% endfor %}
Expand Down
7 changes: 5 additions & 2 deletions dashboard/ui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -73,11 +73,14 @@
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")),
# path('summary_stats.html', redirect("dash-publishingstats-summarystats")),
# 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
27 changes: 27 additions & 0 deletions dashboard/ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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))

0 comments on commit 78e42dd

Please sign in to comment.