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

fix timezone in the downloadable result letter #1464

Merged
merged 1 commit into from
Oct 19, 2023
Merged
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
2 changes: 1 addition & 1 deletion api/namex/VERSION.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.1.32'
__version__ = '1.1.33'
38 changes: 22 additions & 16 deletions api/namex/resources/name_requests/report_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime
from pathlib import Path
import pycountry
from pytz import timezone

import requests
from flask import current_app, jsonify, request
Expand Down Expand Up @@ -45,13 +46,7 @@ def email_consent_letter(self, nr_id):
for applicant in nr_model.applicants:
recipient_emails.append(applicant.emailAddress)
if not nr_model.expirationDate:
nr_service = NameRequestService()
expiry_days = int(nr_service.get_expiry_days(nr_model))
expiry_date = nr_service.create_expiry_date(
start=nr_model.lastUpdate,
expires_in_days=expiry_days
)
nr_model.expirationDate = expiry_date
ReportResource._add_expiry_date(nr_model)
recipients = ','.join(recipient_emails)
template_path = current_app.config.get('REPORT_TEMPLATE_PATH')
email_body = Path(f'{template_path}/emails/consent.md').read_text()
Expand All @@ -74,14 +69,6 @@ def email_report(self, nr_id):
nr_model = Request.query.get(nr_id)
if not nr_model:
return jsonify(message='{nr_id} not found'.format(nr_id=nr_model.id)), HTTPStatus.NOT_FOUND
if not nr_model.expirationDate:
nr_service = NameRequestService()
expiry_days = int(nr_service.get_expiry_days(nr_model))
expiry_date = nr_service.create_expiry_date(
start=nr_model.lastUpdate,
expires_in_days=expiry_days
)
nr_model.expirationDate = expiry_date
report, status_code = ReportResource._get_report(nr_model)
if status_code != HTTPStatus.OK:
return jsonify(message=str(report)), status_code
Expand Down Expand Up @@ -215,6 +202,18 @@ def _get_template():
def _get_template_filename():
return 'nameRequest.html'


@staticmethod
def _add_expiry_date(nr_model):
nr_service = NameRequestService()
expiry_days = int(nr_service.get_expiry_days(nr_model))
expiry_date = nr_service.create_expiry_date(
start=nr_model.lastUpdate,
expires_in_days=expiry_days
)
nr_model.expirationDate = expiry_date


@staticmethod
def _substitute_template_parts(template_code):
template_path = current_app.config.get('REPORT_TEMPLATE_PATH')
Expand Down Expand Up @@ -256,9 +255,16 @@ def _get_template_data(nr_model):
if isXPRO and nr_report_json['nrStateDescription'] == 'Rejected':
nr_report_json['nrStateDescription'] = 'Not Approved'
if nr_report_json['expirationDate']:
tz_aware_date = nr_model.expirationDate.replace(tzinfo=timezone('UTC'))
localized_date = tz_aware_date.astimezone(timezone('US/Pacific'))
nr_report_json['expirationDate'] = localized_date.strftime(DATE_FORMAT)
else:
ReportResource._add_expiry_date(nr_model)
nr_report_json['expirationDate'] = nr_model.expirationDate.strftime(DATE_FORMAT)
if nr_report_json['submittedDate']:
nr_report_json['submittedDate'] = nr_model.submittedDate.strftime('%B %-d, %Y')
tz_aware_date = nr_model.submittedDate.replace(tzinfo=timezone('UTC'))
localized_date = tz_aware_date.astimezone(timezone('US/Pacific'))
nr_report_json['submittedDate'] = localized_date.strftime(DATE_FORMAT)
if nr_report_json['applicants']['countryTypeCd']:
nr_report_json['applicants']['countryName'] = \
pycountry.countries.search_fuzzy(nr_report_json['applicants']['countryTypeCd'])[0].name
Expand Down
Loading