Skip to content

Commit

Permalink
chore: Consolidate timestamp format strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
macdiesel committed Nov 25, 2024
1 parent 0f5c43c commit 9824e70
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion enterprise_catalog/apps/api/v1/views/catalog_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import csv
import time

from enterprise_catalog.apps.catalog.constants import TIMESTAMP_FORMAT

from django.http import StreamingHttpResponse
from rest_framework.decorators import action
from rest_framework.generics import GenericAPIView
Expand Down Expand Up @@ -110,7 +112,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)),
Expand Down
3 changes: 2 additions & 1 deletion enterprise_catalog/apps/api/v1/views/catalog_workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions enterprise_catalog/apps/catalog/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
DISABLE_MODEL_ADMIN_CHANGES_SWITCH,
)

TIMESTAMP_FORMAT = '%Y%m%d%H%M%SZ'

# Algolia timestamp default
ALGOLIA_DEFAULT_TIMESTAMP = (datetime(3000, 1, 1)).timestamp()
Expand Down
3 changes: 2 additions & 1 deletion enterprise_catalog/apps/catalog/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
COURSE_RUN,
LEARNER_PATHWAY,
PROGRAM,
TIMESTAMP_FORMAT,
json_serialized_course_modes,
)
from enterprise_catalog.apps.catalog.models import (
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion enterprise_catalog/apps/catalog/tests/test_algolia_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
LEARNER_PATHWAY,
PROGRAM,
RESTRICTION_FOR_B2B,
TIMESTAMP_FORMAT,
)
from enterprise_catalog.apps.catalog.tests.factories import (
ContentMetadataFactory,
Expand All @@ -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):
Expand Down

0 comments on commit 9824e70

Please sign in to comment.