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

Added ISO formatted strings being allowed as date inputs #34

Merged
merged 8 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -469,7 +469,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(),
"mail_header": mail_header,
Expand All @@ -493,6 +493,18 @@ def filter_parameters(self):

return result

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
55 changes: 55 additions & 0 deletions src/collective/volto/formsupport/tests/test_send_action_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,61 @@ def test_email_body_formated_as_list(
self.assertIn("<strong>Message:</strong> just want to say hi", msg)
self.assertIn("<strong>Name:</strong> John", msg)

def test_send_date(
self,
):
self.document.blocks = {
"form-id": {
"@type": "form",
"send": True,
"email_format": "list",
"subblocks": [
{
"field_id": "date_field_simple",
"field_type": "date",
},
{
"field_id": "date_field_iso",
"field_type": "date",
},
],
},
}
transaction.commit()

response = self.submit_form(
data={
"from": "[email protected]",
"data": [
{
"field_id": "date_field_simple",
"label": "Simple date",
"value": "2024-09-16",
},
{
"field_id": "date_field_iso",
"label": "ISO date",
"value": "2024-09-16T16:20:00Z",
},
],
"subject": "test subject",
"block_id": "form-id",
},
)
transaction.commit()
self.assertEqual(response.status_code, 200)
msg = self.mailhost.messages[0]
if isinstance(msg, bytes) and bytes is not str:
# Python 3 with Products.MailHost 4.10+
msg = msg.decode("utf-8")
msg = re.sub(r"\s+", " ", msg)
self.assertIn("Subject: test subject", msg)
self.assertIn("From: [email protected]", msg)
self.assertIn("To: [email protected]", msg)
self.assertIn("Reply-To: [email protected]", msg)
self.assertIn("<strong>Simple date:</strong> Sep 16, 2024", msg)
self.assertIn("<strong>ISO date:</strong> Sep 16, 2024", msg)

def test_send_xml(self):
self.document.blocks = {
"form-id": {
Expand Down