diff --git a/enterprise_catalog/apps/api/v1/views/catalog_csv.py b/enterprise_catalog/apps/api/v1/views/catalog_csv.py index 9825de8d..556fbf98 100644 --- a/enterprise_catalog/apps/api/v1/views/catalog_csv.py +++ b/enterprise_catalog/apps/api/v1/views/catalog_csv.py @@ -13,6 +13,7 @@ from enterprise_catalog.apps.catalog.algolia_utils import ( get_initialized_algolia_client, ) +from enterprise_catalog.apps.catalog.constants import TIMESTAMP_FORMAT # CatalogCsvView's StreamingHttpResponse requires a File-like class that has a 'write' method @@ -110,7 +111,7 @@ def get(self, request, **kwargs): if invalid_facets: return Response(f'Error: invalid facet(s): {invalid_facets} provided.', status=HTTP_400_BAD_REQUEST) - filename = f'Enterprise-Catalog-Export-{time.strftime("%Y%m%d%H%M%S")}.csv' + filename = f'Enterprise-Catalog-Export-{time.strftime(TIMESTAMP_FORMAT)}.csv' response = StreamingHttpResponse( streaming_content=(self.iter_items(facets, algoliaQuery)), diff --git a/enterprise_catalog/apps/api/v1/views/catalog_workbook.py b/enterprise_catalog/apps/api/v1/views/catalog_workbook.py index a54cc44b..9d2bb210 100644 --- a/enterprise_catalog/apps/api/v1/views/catalog_workbook.py +++ b/enterprise_catalog/apps/api/v1/views/catalog_workbook.py @@ -13,6 +13,7 @@ from enterprise_catalog.apps.catalog.algolia_utils import ( get_initialized_algolia_client, ) +from enterprise_catalog.apps.catalog.constants import TIMESTAMP_FORMAT logger = logging.getLogger(__name__) @@ -143,7 +144,7 @@ def get(self, request, **kwargs): output, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) - filename = f'Enterprise-Catalog-Export-{time.strftime("%Y%m%d%H%M%S")}.xlsx' + filename = f'Enterprise-Catalog-Export-{time.strftime(TIMESTAMP_FORMAT)}.xlsx' response['Content-Disposition'] = f'attachment; filename={filename}' return response diff --git a/enterprise_catalog/apps/catalog/constants.py b/enterprise_catalog/apps/catalog/constants.py index 58ed6e79..08ee1119 100644 --- a/enterprise_catalog/apps/catalog/constants.py +++ b/enterprise_catalog/apps/catalog/constants.py @@ -6,6 +6,8 @@ ) +TIMESTAMP_FORMAT = '%Y%m%d%H%M%SZ' + # Algolia timestamp default ALGOLIA_DEFAULT_TIMESTAMP = (datetime(3000, 1, 1)).timestamp() diff --git a/enterprise_catalog/apps/catalog/tests/factories.py b/enterprise_catalog/apps/catalog/tests/factories.py index 45fab4b4..740a7c66 100644 --- a/enterprise_catalog/apps/catalog/tests/factories.py +++ b/enterprise_catalog/apps/catalog/tests/factories.py @@ -10,6 +10,7 @@ COURSE_RUN, LEARNER_PATHWAY, PROGRAM, + TIMESTAMP_FORMAT, json_serialized_course_modes, ) from enterprise_catalog.apps.catalog.models import ( @@ -180,7 +181,7 @@ def _json_metadata(self): 'overview': 'Pathway for a data engineer.', 'published': True, 'visible_via_association': True, - 'created': datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ'), + 'created': datetime.datetime.utcnow().strftime(TIMESTAMP_FORMAT), 'card_image': { 'card': { 'url': self.card_image_url, diff --git a/enterprise_catalog/apps/catalog/tests/test_algolia_utils.py b/enterprise_catalog/apps/catalog/tests/test_algolia_utils.py index 81ab4523..99a4cf6e 100644 --- a/enterprise_catalog/apps/catalog/tests/test_algolia_utils.py +++ b/enterprise_catalog/apps/catalog/tests/test_algolia_utils.py @@ -15,6 +15,7 @@ LEARNER_PATHWAY, PROGRAM, RESTRICTION_FOR_B2B, + TIMESTAMP_FORMAT, ) from enterprise_catalog.apps.catalog.tests.factories import ( ContentMetadataFactory, @@ -32,7 +33,7 @@ def _days_from_now(days=0): deadline = localized_utcnow() + timedelta(days=days) - return deadline.strftime('%Y-%m-%dT%H:%M:%SZ') + return deadline.strftime(TIMESTAMP_FORMAT) def _get_from_cache(days):