mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-20 03:19:24 +02:00
Gather all existing reports on analytics page
This commit is contained in:
parent
348d777260
commit
56cd0b6d15
5 changed files with 99 additions and 113 deletions
|
@ -357,18 +357,59 @@ class MyUserAdmin(BaseUserAdmin):
|
|||
ordering = ["first_name", "last_name", "email"]
|
||||
|
||||
def get_urls(self):
|
||||
"""Map a new page in admin for analytics."""
|
||||
urlpatterns = super().get_urls()
|
||||
|
||||
# Used to extrapolate a path name, for instance
|
||||
# name="{app_label}_{model_name}_export_data_type"
|
||||
domain_path_meta = self.model._meta.app_label, models.Domain._meta.model_name
|
||||
|
||||
my_urls = [
|
||||
path(
|
||||
"analytics/",
|
||||
self.admin_site.admin_view(self.user_analytics),
|
||||
name="user_analytics",
|
||||
),
|
||||
path(
|
||||
"export_data_type/",
|
||||
self.export_data_type,
|
||||
name="%s_%s_export_data_type" % domain_path_meta,
|
||||
),
|
||||
path(
|
||||
"export_data_full/",
|
||||
self.export_data_full,
|
||||
name="%s_%s_export_data_full" % domain_path_meta,
|
||||
),
|
||||
path(
|
||||
"export_data_federal/",
|
||||
self.export_data_federal,
|
||||
name="%s_%s_export_data_federal" % domain_path_meta,
|
||||
),
|
||||
]
|
||||
|
||||
return my_urls + urlpatterns
|
||||
|
||||
def export_data_type(self, request):
|
||||
# match the CSV example with all the fields
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = 'attachment; filename="domains-by-type.csv"'
|
||||
csv_export.export_data_type_to_csv(response)
|
||||
return response
|
||||
|
||||
def export_data_full(self, request):
|
||||
# Smaller export based on 1
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = 'attachment; filename="current-full.csv"'
|
||||
csv_export.export_data_full_to_csv(response)
|
||||
return response
|
||||
|
||||
def export_data_federal(self, request):
|
||||
# Federal only
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = 'attachment; filename="current-federal.csv"'
|
||||
csv_export.export_data_federal_to_csv(response)
|
||||
return response
|
||||
|
||||
def user_analytics(self, request):
|
||||
last_30_days_applications = models.DomainApplication.objects.filter(
|
||||
created_at__gt=datetime.datetime.today() - datetime.timedelta(days=30)
|
||||
|
@ -1103,60 +1144,11 @@ class DomainAdmin(ListHeaderAdmin):
|
|||
search_fields = ["name"]
|
||||
search_help_text = "Search by domain name."
|
||||
change_form_template = "django/admin/domain_change_form.html"
|
||||
change_list_template = "django/admin/domain_change_list.html"
|
||||
readonly_fields = ["state", "expiration_date", "first_ready", "deleted"]
|
||||
|
||||
# Table ordering
|
||||
ordering = ["name"]
|
||||
|
||||
def export_data_type(self, request):
|
||||
# match the CSV example with all the fields
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = 'attachment; filename="domains-by-type.csv"'
|
||||
csv_export.export_data_type_to_csv(response)
|
||||
return response
|
||||
|
||||
def export_data_full(self, request):
|
||||
# Smaller export based on 1
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = 'attachment; filename="current-full.csv"'
|
||||
csv_export.export_data_full_to_csv(response)
|
||||
return response
|
||||
|
||||
def export_data_federal(self, request):
|
||||
# Federal only
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = 'attachment; filename="current-federal.csv"'
|
||||
csv_export.export_data_federal_to_csv(response)
|
||||
return response
|
||||
|
||||
def get_urls(self):
|
||||
urlpatterns = super().get_urls()
|
||||
|
||||
# Used to extrapolate a path name, for instance
|
||||
# name="{app_label}_{model_name}_export_data_type"
|
||||
info = self.model._meta.app_label, self.model._meta.model_name
|
||||
|
||||
my_url = [
|
||||
path(
|
||||
"export_data_type/",
|
||||
self.export_data_type,
|
||||
name="%s_%s_export_data_type" % info,
|
||||
),
|
||||
path(
|
||||
"export_data_full/",
|
||||
self.export_data_full,
|
||||
name="%s_%s_export_data_full" % info,
|
||||
),
|
||||
path(
|
||||
"export_data_federal/",
|
||||
self.export_data_federal,
|
||||
name="%s_%s_export_data_federal" % info,
|
||||
),
|
||||
]
|
||||
|
||||
return my_url + urlpatterns
|
||||
|
||||
def response_change(self, request, obj):
|
||||
# Create dictionary of action functions
|
||||
ACTION_FUNCTIONS = {
|
||||
|
|
|
@ -112,7 +112,8 @@ html[data-theme="light"] {
|
|||
.change-list .usa-table thead th,
|
||||
body.dashboard,
|
||||
body.change-list,
|
||||
body.change-form {
|
||||
body.change-form,
|
||||
.analytics {
|
||||
color: var(--body-fg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,61 @@
|
|||
{% extends "admin/base_site.html" %}
|
||||
|
||||
{% block content_title %}Registrar Analytics{% endblock %}
|
||||
|
||||
|
||||
{% block content_title %}<h1>Registrar Analytics</h1>{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<ul>
|
||||
|
||||
{% block object-tools %}
|
||||
<ul class="object-tools">
|
||||
<li>
|
||||
<a href="{% url 'admin:registrar_domain_export_data_type' %}" class="button">Export all domain metadata</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'admin:registrar_domain_export_data_full' %}" class="button">Export current-full.csv</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'admin:registrar_domain_export_data_federal' %}" class="button">Export current-federal.csv</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
<div id="content-main" class="analytics">
|
||||
<div class="module">
|
||||
<h2>At a glance</h2>
|
||||
<div class="padding-2">
|
||||
<ul>
|
||||
<li>User Count: {{ data.user_count }}</li>
|
||||
<li>Domain Count: {{ data.domain_count }}</li>
|
||||
<li>Domain applications (last 30 days): {{ data.applications_last_30_days }}</li>
|
||||
<li>Average approval time for applications (last 30 days): {{ data.average_application_approval_time_last_30_days }}</li>
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="module">
|
||||
<h2>Domain growth</h2>
|
||||
<div class="padding-2">
|
||||
{% comment %}
|
||||
Inputs of type date suck for accessibility.
|
||||
We'll need to replace those guys with a django form once we figure out how to hook one onto this page.
|
||||
The challenge is in the path definition in urls. It does NOT like admin/export_data/
|
||||
|
||||
See the commit "Review for ticket #999"
|
||||
{% endcomment %}
|
||||
<div class="display-flex flex-align-baseline flex-justify margin-y-1">
|
||||
<div>
|
||||
<label for="start">Start date:</label>
|
||||
<input type="date" id="start" name="start" value="2018-07-22" min="2018-01-01" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="end">End date:</label>
|
||||
<input type="date" id="end" name="end" value="2023-12-01" min="2023-12-01" />
|
||||
</div>
|
||||
<button id="exportLink" data-export-url="{% url 'admin_export_data' %}" type="button" class="button">Export</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
{% extends "admin/index.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div id="content-main">
|
||||
{% include "admin/app_list.html" with app_list=app_list show_changelinks=True %}
|
||||
<div class="custom-content module">
|
||||
<h2>Reports</h2>
|
||||
<h3>Domain growth report</h3>
|
||||
|
||||
{% comment %}
|
||||
Inputs of type date suck for accessibility.
|
||||
We'll need to replace those guys with a django form once we figure out how to hook one onto this page.
|
||||
The challenge is in the path definition in urls. Itdoes NOT like admin/export_data/
|
||||
|
||||
See the commit "Review for ticket #999"
|
||||
{% endcomment %}
|
||||
|
||||
<div class="display-flex flex-align-baseline flex-justify margin-y-1">
|
||||
<div>
|
||||
<label for="start">Start date:</label>
|
||||
<input type="date" id="start" name="start" value="2018-07-22" min="2018-01-01" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="end">End date:</label>
|
||||
<input type="date" id="end" name="end" value="2023-12-01" min="2023-12-01" />
|
||||
</div>
|
||||
|
||||
<button id="exportLink" data-export-url="{% url 'admin_export_data' %}" type="button" class="button">Export</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,23 +0,0 @@
|
|||
{% extends "admin/change_list.html" %}
|
||||
|
||||
{% block object-tools %}
|
||||
|
||||
<ul class="object-tools">
|
||||
<li>
|
||||
<a href="{% url 'admin:registrar_domain_export_data_type' %}" class="button">Export all domain metadata</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'admin:registrar_domain_export_data_full' %}" class="button">Export current-full.csv</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'admin:registrar_domain_export_data_federal' %}" class="button">Export current-federal.csv</a>
|
||||
</li>
|
||||
{% if has_add_permission %}
|
||||
<li>
|
||||
<a href="{% url 'admin:registrar_domain_add' %}" class="addlink">
|
||||
Add domain
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue