From c1dac136ec261c9239635efb6eb540b602bcb3f3 Mon Sep 17 00:00:00 2001 From: John Tordoff <> Date: Fri, 25 Oct 2024 10:59:29 -0400 Subject: [PATCH] add view name to file download --- api/base/settings/defaults.py | 2 +- api/metrics/renderers.py | 1 + .../institutions/views/test_institution_user_metric_list.py | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/api/base/settings/defaults.py b/api/base/settings/defaults.py index 7bbccb181ec..3f64b47fc75 100644 --- a/api/base/settings/defaults.py +++ b/api/base/settings/defaults.py @@ -359,7 +359,7 @@ MAX_SIZE_OF_ES_QUERY = 10000 DEFAULT_ES_NULL_VALUE = 'N/A' -REPORT_FILENAME_FORMAT = 'osf_report_{date_created}.{format_type}' +REPORT_FILENAME_FORMAT = '{view_name}_{date_created}.{format_type}' CI_ENV = False diff --git a/api/metrics/renderers.py b/api/metrics/renderers.py index 01599dda4dd..1f2f2c0496f 100644 --- a/api/metrics/renderers.py +++ b/api/metrics/renderers.py @@ -65,6 +65,7 @@ def get_filename(self, renderer_context: dict, format_type: str) -> str: if renderer_context and 'view' in renderer_context: current_date = datetime.datetime.now().strftime('%Y-%m') return REPORT_FILENAME_FORMAT.format( + view_name=renderer_context['view'].view_name, date_created=current_date, format_type=format_type, ) diff --git a/api_tests/institutions/views/test_institution_user_metric_list.py b/api_tests/institutions/views/test_institution_user_metric_list.py index 046019e5616..78c6db93d27 100644 --- a/api_tests/institutions/views/test_institution_user_metric_list.py +++ b/api_tests/institutions/views/test_institution_user_metric_list.py @@ -436,6 +436,7 @@ def test_get_report_formats_csv_tsv(self, app, url, institutional_admin, institu current_date = datetime.datetime.now().strftime('%Y-%m') expected_filename = REPORT_FILENAME_FORMAT.format( + view_name='institution-user-metrics', date_created=current_date, format_type=format_type ) @@ -516,6 +517,7 @@ def test_get_report_format_json(self, app, url, institutional_admin, institution current_date = datetime.datetime.now().strftime('%Y-%m') expected_filename = REPORT_FILENAME_FORMAT.format( + view_name='institution-user-metrics', date_created=current_date, format_type='json' ) @@ -601,6 +603,7 @@ def test_csv_tsv_ignores_pagination(self, app, url, institutional_admin, institu current_date = datetime.datetime.now().strftime('%Y-%m') expected_filename = REPORT_FILENAME_FORMAT.format( + view_name='institution-user-metrics', date_created=current_date, format_type=format_type )