Skip to content

Commit f246a24

Browse files
committed
chore: Consolidate timestamp format strings.
1 parent 0f5c43c commit f246a24

5 files changed

Lines changed: 11 additions & 4 deletions

File tree

enterprise_catalog/apps/api/v1/views/catalog_csv.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import csv
33
import time
44

5+
56
from django.http import StreamingHttpResponse
67
from rest_framework.decorators import action
78
from rest_framework.generics import GenericAPIView
@@ -13,6 +14,7 @@
1314
from enterprise_catalog.apps.catalog.algolia_utils import (
1415
get_initialized_algolia_client,
1516
)
17+
from enterprise_catalog.apps.catalog.constants import TIMESTAMP_FORMAT
1618

1719

1820
# CatalogCsvView's StreamingHttpResponse requires a File-like class that has a 'write' method
@@ -110,7 +112,7 @@ def get(self, request, **kwargs):
110112
if invalid_facets:
111113
return Response(f'Error: invalid facet(s): {invalid_facets} provided.', status=HTTP_400_BAD_REQUEST)
112114

113-
filename = f'Enterprise-Catalog-Export-{time.strftime("%Y%m%d%H%M%S")}.csv'
115+
filename = f'Enterprise-Catalog-Export-{time.strftime(TIMESTAMP_FORMAT)}.csv'
114116

115117
response = StreamingHttpResponse(
116118
streaming_content=(self.iter_items(facets, algoliaQuery)),

enterprise_catalog/apps/api/v1/views/catalog_workbook.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from enterprise_catalog.apps.catalog.algolia_utils import (
1414
get_initialized_algolia_client,
1515
)
16+
from enterprise_catalog.apps.catalog.constants import TIMESTAMP_FORMAT
1617

1718

1819
logger = logging.getLogger(__name__)
@@ -143,7 +144,7 @@ def get(self, request, **kwargs):
143144
output,
144145
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
145146
)
146-
filename = f'Enterprise-Catalog-Export-{time.strftime("%Y%m%d%H%M%S")}.xlsx'
147+
filename = f'Enterprise-Catalog-Export-{time.strftime(TIMESTAMP_FORMAT)}.xlsx'
147148
response['Content-Disposition'] = f'attachment; filename={filename}'
148149

149150
return response

enterprise_catalog/apps/catalog/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
)
77

88

9+
TIMESTAMP_FORMAT = '%Y%m%d%H%M%SZ'
10+
911
# Algolia timestamp default
1012
ALGOLIA_DEFAULT_TIMESTAMP = (datetime(3000, 1, 1)).timestamp()
1113

enterprise_catalog/apps/catalog/tests/factories.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
COURSE_RUN,
1111
LEARNER_PATHWAY,
1212
PROGRAM,
13+
TIMESTAMP_FORMAT,
1314
json_serialized_course_modes,
1415
)
1516
from enterprise_catalog.apps.catalog.models import (
@@ -180,7 +181,7 @@ def _json_metadata(self):
180181
'overview': 'Pathway for a data engineer.',
181182
'published': True,
182183
'visible_via_association': True,
183-
'created': datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ'),
184+
'created': datetime.datetime.utcnow().strftime(TIMESTAMP_FORMAT),
184185
'card_image': {
185186
'card': {
186187
'url': self.card_image_url,

enterprise_catalog/apps/catalog/tests/test_algolia_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
LEARNER_PATHWAY,
1616
PROGRAM,
1717
RESTRICTION_FOR_B2B,
18+
TIMESTAMP_FORMAT,
1819
)
1920
from enterprise_catalog.apps.catalog.tests.factories import (
2021
ContentMetadataFactory,
@@ -32,7 +33,7 @@
3233

3334
def _days_from_now(days=0):
3435
deadline = localized_utcnow() + timedelta(days=days)
35-
return deadline.strftime('%Y-%m-%dT%H:%M:%SZ')
36+
return deadline.strftime(TIMESTAMP_FORMAT)
3637

3738

3839
def _get_from_cache(days):

0 commit comments

Comments
 (0)