Add Service.get_days_of_retention helper method

Data retention lookup by type is only performed to get the number
of days, so we can update the service method to return the number
or the default directly.
This commit is contained in:
Alexey Bezhan
2018-12-03 17:57:11 +00:00
parent 7a7a9ae854
commit b787ca6e5b
3 changed files with 6 additions and 14 deletions

View File

@@ -3,7 +3,6 @@
from flask import (
Response,
abort,
current_app,
jsonify,
redirect,
render_template,
@@ -226,9 +225,7 @@ def get_notifications(service_id, message_type, status_override=None):
service_data_retention_days = None
if message_type is not None:
service_data_retention_days = current_service.get_data_retention_by_type(
message_type
).get('days_of_retention', current_app.config['ACTIVITY_STATS_LIMIT_DAYS'])
service_data_retention_days = current_service.get_days_of_retention(message_type)
if request.path.endswith('csv') and current_user.has_permissions('view_activity'):
return Response(
@@ -406,9 +403,7 @@ def get_job_partials(job, template):
counts=_get_job_counts(job),
status=filter_args['status']
)
service_data_retention_days = current_service.get_data_retention_by_type(
template['template_type']
).get('days_of_retention', current_app.config['ACTIVITY_STATS_LIMIT_DAYS'])
service_data_retention_days = current_service.get_days_of_retention(template['template_type'])
return {
'counts': counts,

View File

@@ -8,7 +8,6 @@ from dateutil import parser
from flask import (
Response,
abort,
current_app,
jsonify,
render_template,
request,
@@ -197,9 +196,7 @@ def download_notifications_csv(service_id):
filter_args = parse_filter_args(request.args)
filter_args['status'] = set_status_filters(filter_args)
service_data_retention_days = current_service.get_data_retention_by_type(
filter_args.get('message_type')[0]
).get('days_of_retention', current_app.config['ACTIVITY_STATS_LIMIT_DAYS'])
service_data_retention_days = current_service.get_days_of_retention(filter_args.get('message_type')[0])
return Response(
stream_with_context(
generate_notifications_csv(

View File

@@ -1,4 +1,4 @@
from flask import abort
from flask import abort, current_app
from notifications_utils.field import Field
from werkzeug.utils import cached_property
@@ -273,11 +273,11 @@ class Service():
None
)
def get_data_retention_by_type(self, notification_type):
def get_days_of_retention(self, notification_type):
return next(
(dr for dr in self.data_retention if dr['notification_type'] == notification_type),
{}
)
).get('days_of_retention', current_app.config['ACTIVITY_STATS_LIMIT_DAYS'])
@property
def email_branding_id(self):