Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Consolidate timestamp format strings. #1005

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion enterprise_catalog/apps/api/v1/views/catalog_csv.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


# CatalogCsvView's StreamingHttpResponse requires a File-like class that has a 'write' method
Expand Down Expand Up @@ -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)),
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
2 changes: 2 additions & 0 deletions enterprise_catalog/apps/catalog/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
)


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
Loading