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

Send dates as formatted strings #34

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def prepare_message(self):
request=self.request,
)
parameters = {
"parameters": self.filter_parameters(),
"parameters": self.format_fields(self.filter_parameters()),
"url": self.context.absolute_url(),
"title": self.context.Title(),
}
Expand All @@ -370,6 +370,18 @@ def filter_parameters(self):
if x.get("field_id", "") not in skip_fields
]

def format_fields(self, fields):
formatted_fields = []
field_ids = [field.get("field_id") for field in self.block.get("subblocks", [])]
for field in fields:
field_id = field.get("field_id", "")
if field_id:
field_index = field_ids.index(field_id)
if self.block["subblocks"][field_index].get("field_type") == "date":
field["value"] = api.portal.get_localized_time(field["value"])
formatted_fields.append(field)
return formatted_fields

def send_mail(self, msg, charset):
host = api.portal.get_tool(name="MailHost")
# we set immediate=True because we need to catch exceptions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_export_csv(self):
self.assertEqual(sorted_data[1][:-1], ["just want to say hi", "John"])

# check date column. Skip seconds because can change during test
now = datetime.utcnow().strftime("%Y-%m-%dT%H:%M")
now = datetime.now().strftime("%Y-%m-%dT%H:%M")
self.assertTrue(sorted_data[0][-1].startswith(now))
self.assertTrue(sorted_data[1][-1].startswith(now))

Expand Down Expand Up @@ -307,6 +307,6 @@ def test_data_id_mapping(self):
self.assertEqual(sorted_data[1][:-1], ["just want to say hi", "John"])

# check date column. Skip seconds because can change during test
now = datetime.utcnow().strftime("%Y-%m-%dT%H:%M")
now = datetime.now().strftime("%Y-%m-%dT%H:%M")
self.assertTrue(sorted_data[0][-1].startswith(now))
self.assertTrue(sorted_data[1][-1].startswith(now))
Loading