mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-02 23:20:56 -04:00
Put the download csv link on the activity page.
Still needs some tests, probably some refactoring as well.
This commit is contained in:
70
app/utils.py
70
app/utils.py
@@ -1,5 +1,7 @@
|
||||
import re
|
||||
import csv
|
||||
from itertools import chain
|
||||
|
||||
import pytz
|
||||
from io import StringIO
|
||||
from os import path
|
||||
@@ -28,7 +30,8 @@ from notifications_utils.template import (
|
||||
LetterImageTemplate,
|
||||
LetterPreviewTemplate,
|
||||
)
|
||||
|
||||
from orderedset._orderedset import OrderedSet
|
||||
from werkzeug.datastructures import MultiDict
|
||||
|
||||
SENDING_STATUSES = ['created', 'pending', 'sending']
|
||||
DELIVERED_STATUSES = ['delivered', 'sent']
|
||||
@@ -132,21 +135,36 @@ def generate_notifications_csv(**kwargs):
|
||||
yield ','.join(fieldnames) + '\n'
|
||||
|
||||
while kwargs['page']:
|
||||
# if job_id then response looks different
|
||||
notifications_resp = notification_api_client.get_notifications_for_service(**kwargs)
|
||||
notifications = notifications_resp['notifications']
|
||||
for notification in notifications:
|
||||
values = [
|
||||
notification['row_number'],
|
||||
notification['recipient'],
|
||||
notification['template_name'],
|
||||
notification['template_type'],
|
||||
notification['job_name'],
|
||||
notification['status'],
|
||||
notification['created_at']
|
||||
]
|
||||
line = ','.join(str(i) for i in values) + '\n'
|
||||
yield line
|
||||
|
||||
if kwargs['job_id']:
|
||||
for notification in notifications:
|
||||
values = [
|
||||
notification['row_number'],
|
||||
notification['recipient'],
|
||||
notification['template_name'],
|
||||
notification['template_type'],
|
||||
notification['job_name'],
|
||||
notification['status'],
|
||||
notification['created_at']
|
||||
]
|
||||
line = ','.join(str(i) for i in values) + '\n'
|
||||
yield line
|
||||
else:
|
||||
# Change here
|
||||
for notification in notifications:
|
||||
values = [
|
||||
notification.get('row_number', None),
|
||||
notification['to'],
|
||||
notification['template']['name'],
|
||||
notification['template']['template_type'],
|
||||
notification.get('job_name', None),
|
||||
notification['status'],
|
||||
notification['created_at']
|
||||
]
|
||||
line = ','.join(str(i) for i in values) + '\n'
|
||||
yield line
|
||||
if notifications_resp['links'].get('next'):
|
||||
kwargs['page'] += 1
|
||||
else:
|
||||
@@ -381,3 +399,27 @@ def get_cdn_domain():
|
||||
domain = parsed_uri.netloc[len(subdomain + '.'):]
|
||||
|
||||
return "static-logos.{}".format(domain)
|
||||
|
||||
|
||||
def parse_filter_args(filter_dict):
|
||||
if not isinstance(filter_dict, MultiDict):
|
||||
filter_dict = MultiDict(filter_dict)
|
||||
|
||||
return MultiDict(
|
||||
(
|
||||
key,
|
||||
(','.join(filter_dict.getlist(key))).split(',')
|
||||
)
|
||||
for key in filter_dict.keys()
|
||||
if ''.join(filter_dict.getlist(key))
|
||||
)
|
||||
|
||||
|
||||
def set_status_filters(filter_args):
|
||||
status_filters = filter_args.get('status', [])
|
||||
return list(OrderedSet(chain(
|
||||
(status_filters or REQUESTED_STATUSES),
|
||||
DELIVERED_STATUSES if 'delivered' in status_filters else [],
|
||||
SENDING_STATUSES if 'sending' in status_filters else [],
|
||||
FAILURE_STATUSES if 'failed' in status_filters else []
|
||||
)))
|
||||
|
||||
Reference in New Issue
Block a user