Skip to content

Commit

Permalink
431 fix missing field template (#444)
Browse files Browse the repository at this point in the history
* fixed report_service error

* fixed report_service error

* fixed migrations file

* fixed migrations file

* fixed migrations file

* fixed fe1a62b01dfa_

* fixed fe1a62b01dfa_
  • Loading branch information
hanlunBCRegistries authored Oct 29, 2024
1 parent 907cfcd commit 54190ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div class="pt-2">{{recognition_date_time}}</div>
<div class="pt-2">
{% if annualReport.annualGeneralMeetingDate %}
{{ annualReport.annualGeneralMeetingDate | strftime("%B %d, %Y") }}
{{ annualReport.annualGeneralMeetingDate}}
{% else %}
No AGM
{% endif %}
Expand Down
20 changes: 20 additions & 0 deletions api/src/business_ar_api/services/report_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from http import HTTPStatus
from pathlib import Path
from typing import Final
from datetime import datetime, date

import requests
from flask import current_app, jsonify
Expand Down Expand Up @@ -76,6 +77,21 @@ def generate_report(self, filing_id: int, report_key: str):
if response.status_code != HTTPStatus.OK:
return jsonify(message=str(response.content)), response.status_code
return response.content, response.status_code

def _format_all_dates(self, obj):
"""Recursively format all datetime objects in the data structure to strings."""
if isinstance(obj, dict):
for key, value in obj.items():
if isinstance(value, (datetime, date)):
obj[key] = value.strftime(OUTPUT_DATE_FORMAT)
elif isinstance(value, (dict, list)):
self._format_all_dates(value)
elif isinstance(obj, list):
for index, item in enumerate(obj):
if isinstance(item, (datetime, date)):
obj[index] = item.strftime(OUTPUT_DATE_FORMAT)
elif isinstance(item, (dict, list)):
self._format_all_dates(item)

def _get_report_filename(self):
"""Get the report filename."""
Expand Down Expand Up @@ -109,6 +125,10 @@ def _get_template_data(self):
self._set_description(filing)
self._set_meta_info(filing)
self._set_registrar_info(filing)

# Format all datetime objects in the filing data
self._format_all_dates(filing)

return filing

def _set_registrar_info(self, filing):
Expand Down

0 comments on commit 54190ec

Please sign in to comment.