Skip to content

Commit 6f32114

Browse files
committed
refactor mailnotification templates to make them overrideable with BrowserViews or jbot
1 parent 76e5f0f commit 6f32114

File tree

10 files changed

+344
-344
lines changed

10 files changed

+344
-344
lines changed

src/bda/plone/orders/browser/templates/order_done.pt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<p tal:content="view/text">Text goes here</p>
3131

3232
<a href=""
33-
class="payment_button standalone"
33+
class="btn btn-primary"
3434
tal:attributes="href context/absolute_url"
3535
i18n:translate="order_done_continue">continue</a>
3636

src/bda/plone/orders/configure.zcml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<include file="profiles.zcml" />
1717
<include file="upgrades.zcml" />
1818
<include package=".browser" />
19+
<include package=".mailnotifytemplates" />
1920
<include package=".restapi" />
2021

2122
<!-- roles -->

src/bda/plone/orders/mailnotify.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@
1818
from bda.plone.orders.mailtemplates import get_order_templates
1919
from bda.plone.orders.mailtemplates import get_reservation_templates
2020
from bda.plone.orders.mailtemplates import get_stock_threshold_reached_templates
21-
from chameleon import PageTemplateLoader
2221
from decimal import Decimal
2322
from email.mime.multipart import MIMEMultipart
2423
from email.mime.text import MIMEText
2524
from email.utils import formataddr
2625
from plone import api
2726
from Products.CMFPlone.utils import safe_unicode
27+
from zope.component import getMultiAdapter
2828
from zope.component.hooks import getSite
2929
from zope.globalrequest import getRequest
3030
from zope.i18n import translate
3131

3232
import logging
33-
import os
3433
import textwrap
3534

3635

@@ -306,9 +305,6 @@ def __call__(
306305
)
307306

308307

309-
MAIL_TEMPLATES_DIRECTORY = os.path.join(os.path.dirname(__file__), "mailtemplates")
310-
311-
312308
def create_html_mail_body(context, template_name, template_data):
313309
"""Creates a rendered mail body
314310
@@ -321,10 +317,7 @@ def create_html_mail_body(context, template_name, template_data):
321317
template_data
322318
Dict containing data passed to template.
323319
"""
324-
templates = PageTemplateLoader(
325-
MAIL_TEMPLATES_DIRECTORY, translate=ZPTTranslator(), debug=True
326-
)
327-
template = templates["{}.pt".format(template_name)]
320+
template = getMultiAdapter((context, getRequest()), name=template_name)
328321
template_data["ascur"] = ascur
329322
return template(**template_data)
330323

src/bda/plone/orders/mailnotifytemplates/__init__.py

Whitespace-only changes.

src/bda/plone/orders/mailtemplates/booking_cancelled.pt renamed to src/bda/plone/orders/mailnotifytemplates/booking_cancelled.pt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,28 @@
55

66
<head></head>
77

8-
<body>
8+
<body tal:define="
9+
order options/order;
10+
booking options/booking;
11+
">
912
<h1 i18n:translate="order_mail_booking_cancelled_heading">
1013
One of your bookings was cancelled
1114
</h1>
1215

1316
<strong i18n:translate="order_mail_date">Date</strong>:
14-
<tal:date replace="order['date']" />
17+
${order/date}
1518
<br />
1619

1720
<strong i18n:translate="order_mail_ordernumber">Ordernumber</strong>:
18-
<tal:ordernumber replace="order['ordernumber']" />
21+
${order/ordernumber}
1922
<br />
2023

2124
<strong i18n:translate="order_mail_cancelled_item">Cancelled item</strong>:
22-
<tal:cancelled_item replace="booking['title']" />
25+
${booking7title']}
2326
<br />
2427

2528
<strong i18n:translate="order_mail_order_details">Order details</strong>:
26-
<a href="${order['portal_url'] + '/@@showorder?ordernumber=' + order['ordernumber']}"
29+
<a href="${order/portal_url}/@@showorder?ordernumber=${order/ordernumber}"
2730
i18n:translate="order_mail_click_here">
2831
Click here
2932
</a>

src/bda/plone/orders/mailtemplates/booking_reserved_to_ordered.pt renamed to src/bda/plone/orders/mailnotifytemplates/booking_reserved_to_ordered.pt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55

66
<head></head>
77

8-
<body>
8+
<body tal:define="
9+
order options/order;
10+
booking options/booking;
11+
">
912
<h1 i18n:translate="order_mail_booking_reserved_to_ordered_heading">
1013
Your reserved item is now available and our order is being processed
1114
</h1>
1215

1316
<strong i18n:translate="order_mail_date">Date</strong>:
14-
<tal:date replace="order['date']" />
17+
${order/date}
1518
<br />
1619

1720
<strong i18n:translate="order_mail_ordernumber">Ordernumber</strong>:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<configure xmlns="http://namespaces.zope.org/zope"
2+
xmlns:plone="http://namespaces.plone.org/plone"
3+
xmlns:browser="http://namespaces.zope.org/browser"
4+
xmlns:zcml="http://namespaces.zope.org/zcml">
5+
6+
<browser:page
7+
for="*"
8+
name="booking_cancelled"
9+
template="booking_cancelled.pt"
10+
permission="zope2.View"
11+
layer="..interfaces.IOrdersExtensionLayer" />
12+
13+
<browser:page
14+
for="*"
15+
name="booking_reserved_to_ordered"
16+
template="booking_reserved_to_ordered.pt"
17+
permission="zope2.View"
18+
layer="..interfaces.IOrdersExtensionLayer" />
19+
20+
<browser:page
21+
for="*"
22+
name="order_success"
23+
template="order_success.pt"
24+
permission="zope2.View"
25+
layer="..interfaces.IOrdersExtensionLayer" />
26+
27+
<browser:page
28+
for="*"
29+
name="stock_threshold_reached"
30+
template="stock_threshold_reached.pt"
31+
permission="zope2.View"
32+
layer="..interfaces.IOrdersExtensionLayer" />
33+
34+
</configure>

0 commit comments

Comments
 (0)