mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 11:23:48 -05:00
fixed duplicates to notification by adding aggregate
This commit is contained in:
@@ -29,6 +29,7 @@ from app.utils.csv import Spreadsheet
|
||||
from app.utils.pagination import generate_next_dict, generate_previous_dict
|
||||
from app.utils.time import get_current_financial_year
|
||||
from app.utils.user import user_has_permissions
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
@main.route("/services/<uuid:service_id>/dashboard")
|
||||
@@ -47,22 +48,31 @@ def service_dashboard(service_id):
|
||||
if not current_user.has_permissions("view_activity"):
|
||||
return redirect(url_for("main.choose_template", service_id=service_id))
|
||||
|
||||
notifications = notification_api_client.get_notifications_for_service(
|
||||
notifications_response = notification_api_client.get_notifications_for_service(
|
||||
service_id=service_id,
|
||||
)["notifications"]
|
||||
|
||||
job_response = job_api_client.get_jobs(service_id)
|
||||
|
||||
service_data_retention_days = 7
|
||||
jobs = [
|
||||
|
||||
aggregate_notifications_by_job = defaultdict(list)
|
||||
for notification in notifications_response:
|
||||
job_id = notification.get("job", {}).get("id")
|
||||
if job_id:
|
||||
aggregate_notifications_by_job[job_id].append(notification)
|
||||
|
||||
job_and_notifications = [
|
||||
{
|
||||
"job_id": job["id"],
|
||||
"time_left": get_time_left(job["created_at"]),
|
||||
"download_link": url_for(
|
||||
".view_job_csv", service_id=current_service.id, job_id=job["id"]
|
||||
),
|
||||
"view_job_link": url_for(
|
||||
".view_job", service_id=current_service.id, job_id=job["id"]
|
||||
),
|
||||
"notification_count": job["notification_count"],
|
||||
"created_by": job["created_by"],
|
||||
"notifications": aggregate_notifications_by_job.get(job["id"], []),
|
||||
}
|
||||
for job in job_response["data"]
|
||||
]
|
||||
@@ -70,8 +80,7 @@ def service_dashboard(service_id):
|
||||
"views/dashboard/dashboard.html",
|
||||
updates_url=url_for(".service_dashboard_updates", service_id=service_id),
|
||||
partials=get_dashboard_partials(service_id),
|
||||
notifications=notifications,
|
||||
jobs=jobs,
|
||||
job_and_notifications=job_and_notifications,
|
||||
service_data_retention_days=service_data_retention_days,
|
||||
)
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
{{ ajax_block(partials, updates_url, 'totals') }}
|
||||
|
||||
{{ ajax_block(partials, updates_url, 'template-statistics') }}
|
||||
|
||||
<h2 class="margin-top-4 margin-bottom-1">Recent Batches</h2>
|
||||
<div class='job-table'>
|
||||
<table class="usa-table usa-table--borderless width-full">
|
||||
@@ -55,37 +54,37 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for notification in notifications[:5] %}
|
||||
{% if notification %}
|
||||
<tr class="table-row" id="{{ notification.job.id }}">
|
||||
<th class="table-field">
|
||||
{{ notification.job.original_file_name if notification.job.original_file_name else 'Manually entered number'}}
|
||||
<br>
|
||||
<a class="usa-link file-list-filename" href="/services/{{ notification.service }}/jobs/{{ notification.job.id }}">View Batch</a>
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{{ notification.template.name }}
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{{ notification.created_at | format_datetime_short_america }}
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{{ notification.created_by.name }}
|
||||
</th>
|
||||
{% set job_available = jobs|selectattr('job_id', 'equalto', notification.job.id)|first %}
|
||||
<th class="table-field">
|
||||
{{ job_available.notification_count if job_available else ''}}
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{% if job_available and job_available.time_left != "Data no longer available" %}
|
||||
<a class="usa-link file-list-filename" href="{{ job_available.download_link }}">
|
||||
{{ "Download" if job_available.job_id else '' }}</a>
|
||||
<span class="usa-hint">{{ job_available.time_left }}</span>
|
||||
{% elif job_available %}
|
||||
<span>{{ job_available.time_left }}</span>
|
||||
{% endif %}
|
||||
</th>
|
||||
</tr>
|
||||
{% for job in job_and_notifications[:5] %}
|
||||
{% if job.job_id and job.notifications %}
|
||||
{% for notification in job.notifications %}
|
||||
<tr class="table-row" id="{{ job.job_id }}">
|
||||
<th class="table-field">
|
||||
{{ notification.job.original_file_name if notification.job.original_file_name else 'Manually entered number'}}
|
||||
<br>
|
||||
<a class="usa-link file-list-filename" href="{{ job.view_job_link }}">View Batch</a>
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{{ notification.template.name }}
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{{ notification.created_at | format_datetime_short_america }}
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{{ notification.created_by.name }}
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{{ job.notification_count}}
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{% if notification and job.time_left != "Data no longer available" %}
|
||||
<a class="usa-link file-list-filename" href="{{ job.download_link }}">Download</a>
|
||||
<span class="usa-hint">{{ job.time_left }}</span>
|
||||
{% elif job %}
|
||||
<span>{{ job.time_left }}</span>
|
||||
{% endif %}
|
||||
</th>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user