mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-15 07:18:58 -04:00
Refactored to be more pythonic
Removed the nested for loops and refactored to be pythonic so it is more maintainable in future.
This commit is contained in:
@@ -116,23 +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)
|
||||||
|
|
||||||
months = [
|
def get_monthly_template_stats(month_name, stats):
|
||||||
{
|
return {
|
||||||
'name': yyyy_mm_to_datetime(month).strftime('%B'),
|
'name': month_name,
|
||||||
'templates_used': [],
|
'templates_used': [
|
||||||
}
|
{
|
||||||
for month in get_months_for_financial_year(year, time_format='%Y-%m')
|
|
||||||
]
|
|
||||||
|
|
||||||
for i, d in enumerate(months):
|
|
||||||
for stat in stats:
|
|
||||||
if d['name'] == calendar.month_name[int(stat['month'])]:
|
|
||||||
d['templates_used'].append({
|
|
||||||
'id': stat['template_id'],
|
'id': stat['template_id'],
|
||||||
'name': stat['name'],
|
'name': stat['name'],
|
||||||
'type': stat['type'],
|
'type': stat['type'],
|
||||||
'requested_count': stat['count']
|
'requested_count': stat['count']
|
||||||
})
|
}
|
||||||
|
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',
|
||||||
|
|||||||
Reference in New Issue
Block a user