Skip to content

Commit

Permalink
Send date, time and url in email if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffersonBledsoe committed Jan 20, 2025
1 parent b258131 commit cf6fca1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/collective/volto/formsupport/adapters/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collective.volto.formsupport.interfaces import ICaptchaSupport
from collective.volto.formsupport.interfaces import IPostAdapter
from collective.volto.formsupport.restapi.services.submit_form.field import (
construct_field,
construct_fields,
)
from collective.volto.formsupport.utils import get_blocks
Expand All @@ -18,6 +19,7 @@

import math
import os
from datetime import datetime


@implementer(IPostAdapter)
Expand Down Expand Up @@ -225,7 +227,18 @@ def filter_parameters(self):
"""
do not send attachments fields.
"""
return [field for field in self.format_fields() if field.send_in_email]
fields = [field for field in self.format_fields() if field.send_in_email]

additionalInfo = self.block['sendAdditionalInfo']

if "date" in additionalInfo:
fields.append(construct_field({'field_id': 'date', 'label': 'Date', 'field_type': 'date', 'value': datetime.now()}))
if "time" in additionalInfo:
fields.append(construct_field({'field_id': 'time', 'label': 'Time','field_type': 'time', 'value': datetime.now()}))
if "currentUrl" in additionalInfo:
fields.append(construct_field({'field_id': 'url', 'label': 'URL', 'value': self.context.absolute_url_path()}))

return fields

def format_fields(self):
fields_data = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class DateField(Field):
def display_value(self):
return api.portal.get_localized_time(self.internal_value)

class TimeField(Field):
def display_value(self):
return api.portal.get_localized_time(self.internal_value, time_only=True)


def construct_field(field_data):
if field_data.get("widget") == "single_choice":
Expand All @@ -104,6 +108,8 @@ def construct_field(field_data):
return EmailField(field_data)
elif field_data.get("field_type") == "date":
return DateField(field_data)
elif field_data.get("field_type") == "time":
return TimeField(field_data)

return Field(field_data)

Expand Down

0 comments on commit cf6fca1

Please sign in to comment.