Skip to content

Commit

Permalink
Configurable header and footer (#52)
Browse files Browse the repository at this point in the history
* Configurable header and footer

* Changes

* Review requests

* Update post.py

* Update post.py

* fix dependencies

* Update src/collective/volto/formsupport/restapi/services/submit_form/post.py

* Update src/collective/volto/formsupport/browser/send_mail_template_table.pt

* zpretty

---------

Co-authored-by: Mauro Amico <mauro.amico@gmail.com>
  • Loading branch information
folix-01 and mamico authored Jul 4, 2024
1 parent 5c6e611 commit 97dcc66
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Changelog
3.0.3 (unreleased)
------------------

- Configurable header and footer for email message.
[folix-01]
- Subject templating
[folix-01]

- Handle the edge cases where the `blocks` attribute is not set.
[mamico]

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Zope = [
]
python-dateutil = ['dateutil']
'souper.plone' = ['souper', 'repoze.catalog']
beautifulsoup4 = ['bs4']
# extra packages
ignore-packages = [
# these are packages defined in extras_require
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"Products.PortalTransforms",
"souper.plone",
"click",
"beautifulsoup4",
"pyotp",
],
extras_require={
Expand Down
26 changes: 18 additions & 8 deletions src/collective/volto/formsupport/browser/send_mail_template.pt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
parameters python:options.get('parameters', {});
url python:options.get('url', '');
title python:options.get('title', '');
mail_header python:options.get('mail_header', '');
mail_footer python:options.get('mail_footer', '');
"
i18n:domain="collective.volto.formsupport"
>
<header>
<tal:element tal:replace="structure mail_header" />
</header>
<ul>
<tal:field repeat="field parameters">
<li tal:define="
Expand All @@ -17,12 +22,17 @@
</li>
</tal:field>
</ul>
<p i18n:translate="send_mail_text">
A new form has been submitted from
<a tal:attributes="
href url;
"><strong tal:content="url"
i18n:name="url"
>url</strong></a>
</p>
<footer>
<tal:element tal:replace="structure mail_footer" />
<tal:element tal:condition="python:not mail_footer ">
<p i18n:translate="send_mail_text">
A new form has been submitted from
<a tal:attributes="
href url;
"><strong tal:content="url"
i18n:name="url"
>url</strong></a>
</p>
</tal:element>
</footer>
</tal:root>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
parameters python:options.get('parameters', {});
url python:options.get('url', '');
title python:options.get('title', '');
mail_header python:options.get('mail_header', '');
mail_footer python:options.get('mail_footer', '');
"
i18n:domain="collective.volto.formsupport"
>
Expand All @@ -11,8 +13,13 @@
text-align: start;
}
</style>
<header>
<tal:element tal:replace="structure mail_header" />
<tal:element tal:condition="python:not mail_header">
<caption i18n:translate="send_mail_text_table">Form submission data for ${title}</caption>
</tal:element>
</header>
<table border="1">
<caption i18n:translate="send_mail_text_table">Form submission data for ${title}</caption>
<thead>
<tr role="row">
<th align="left"
Expand Down Expand Up @@ -44,4 +51,7 @@
</tal:field>
</tbody>
</table>
<footer>
<tal:element tal:replace="structure mail_footer" />
</footer>
</tal:root>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from bs4 import BeautifulSoup
from collective.volto.formsupport import _
from collective.volto.formsupport.interfaces import ICaptchaSupport
from collective.volto.formsupport.interfaces import IFormDataStore
Expand Down Expand Up @@ -425,6 +426,14 @@ def send_data(self):
self.send_mail(msg=acknowledgement_mail, charset=charset)

def prepare_message(self):

mail_header = self.block.get("mail_header", {}).get("data", "")
mail_footer = self.block.get("mail_footer", {}).get("data", "")

# Check if there is content
mail_header = BeautifulSoup(mail_header).get_text() if mail_header else None
mail_footer = BeautifulSoup(mail_footer).get_text() if mail_footer else None

email_format_page_template_mapping = {
"list": "send_mail_template",
"table": "send_mail_template_table",
Expand All @@ -443,6 +452,8 @@ def prepare_message(self):
"parameters": self.filter_parameters(),
"url": self.context.absolute_url(),
"title": self.context.Title(),
"mail_header": mail_header,
"mail_footer": mail_footer,
}
return message_template(**parameters)

Expand Down

0 comments on commit 97dcc66

Please sign in to comment.