mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 17:09:49 -04:00
Merge pull request #1654 from alphagov/rc-update-template-usage-to-use-new-end-point
Updated link to for browsing to financial years
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import calendar
|
import calendar
|
||||||
from collections import defaultdict
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from flask import (
|
from flask import (
|
||||||
@@ -117,18 +116,25 @@ def template_usage(service_id):
|
|||||||
|
|
||||||
stats = sorted(stats, key=lambda x: (x['count']), reverse=True)
|
stats = sorted(stats, key=lambda x: (x['count']), reverse=True)
|
||||||
|
|
||||||
templates_by_month = defaultdict(list)
|
def get_monthly_template_stats(month_name, stats):
|
||||||
for stat in stats:
|
return {
|
||||||
templates_by_month[int(stat['month'])].append({
|
'name': month_name,
|
||||||
'name': stat['name'],
|
'templates_used': [
|
||||||
'type': stat['type'],
|
{
|
||||||
'requested_count': stat['count']
|
'id': stat['template_id'],
|
||||||
})
|
'name': stat['name'],
|
||||||
months = [{
|
'type': stat['type'],
|
||||||
'name': calendar.month_name[k],
|
'requested_count': stat['count']
|
||||||
'templates_used': v
|
}
|
||||||
} for k, v in templates_by_month.items()
|
for stat in stats
|
||||||
]
|
if calendar.month_name[int(stat['month'])] == month_name
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
months = [
|
||||||
|
get_monthly_template_stats(month, stats)
|
||||||
|
for month in get_months_for_financial_year(year, time_format='%B')
|
||||||
|
]
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/dashboard/all-template-statistics.html',
|
'views/dashboard/all-template-statistics.html',
|
||||||
@@ -142,7 +148,7 @@ def template_usage(service_id):
|
|||||||
for month in months
|
for month in months
|
||||||
),
|
),
|
||||||
years=get_tuples_of_financial_years(
|
years=get_tuples_of_financial_years(
|
||||||
partial(url_for, '.template_history', service_id=service_id),
|
partial(url_for, '.template_usage', service_id=service_id),
|
||||||
end=current_financial_year,
|
end=current_financial_year,
|
||||||
),
|
),
|
||||||
selected_year=year
|
selected_year=year
|
||||||
|
|||||||
Reference in New Issue
Block a user