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

Configurable header and footer #52

Merged
merged 10 commits into from
Jul 4, 2024
Merged
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
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 @@ -418,6 +419,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 @@ -436,6 +445,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