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

Refactor mailnotification templates to make them better overrideable #66

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 8 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ After that you can start customizing the order process:
.. code-block:: python

def patchShop():
patchMailTemplates()
patchOrderExport()


Expand All @@ -65,19 +64,16 @@ WARNING:
HTML Templates
^^^^^^^^^^^^^^

Default HTML templates are located at ``bda.plone.orders:mailtemplates``.
To customize them, copy the entire template folder to your integration package
and patch ``bda.plone.orders.mailnotify.MAIL_TEMPLATES_DIRECTORY`` like so:
Default HTML templates are located at ``bda.plone.orders.mailnotifytemplates``
and registered as ``BrowserViews``. You can override the templates using
``z3c.jbot``.

.. code-block:: python

from bda.plone.orders import mailnotify
import os
WARNING:

mailnotify.MAIL_TEMPLATES_DIRECTORY = os.path.join(
os.path.dirname(__file__),
'mailtemplates'
)
As of ``bda.plone.orders`` 2.0b3 the location of the mailnotification
templates moved from the folder ``mailtemplates`` to the module
``mailnotifytemplates``. Please refactor your patches to jbot templates
or BrowserViews.


Text Templates
Expand Down
2 changes: 1 addition & 1 deletion src/bda/plone/orders/browser/templates/order_done.pt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<p tal:content="view/text">Text goes here</p>

<a href=""
class="payment_button standalone"
class="btn btn-primary"
tal:attributes="href context/absolute_url"
i18n:translate="order_done_continue">continue</a>

Expand Down
1 change: 1 addition & 0 deletions src/bda/plone/orders/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<include file="profiles.zcml" />
<include file="upgrades.zcml" />
<include package=".browser" />
<include package=".mailnotifytemplates" />
<include package=".restapi" />

<!-- roles -->
Expand Down
17 changes: 11 additions & 6 deletions src/bda/plone/orders/mailnotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
from email.utils import formataddr
from plone import api
from Products.CMFPlone.utils import safe_unicode
from zope.component import getMultiAdapter
from zope.component.hooks import getSite
from zope.globalrequest import getRequest
from zope.i18n import translate

import logging
import os
import textwrap


Expand Down Expand Up @@ -306,7 +306,7 @@ def __call__(
)


MAIL_TEMPLATES_DIRECTORY = os.path.join(os.path.dirname(__file__), "mailtemplates")
MAIL_TEMPLATES_DIRECTORY = ""


def create_html_mail_body(context, template_name, template_data):
Expand All @@ -321,10 +321,15 @@ def create_html_mail_body(context, template_name, template_data):
template_data
Dict containing data passed to template.
"""
templates = PageTemplateLoader(
MAIL_TEMPLATES_DIRECTORY, translate=ZPTTranslator(), debug=True
)
template = templates["{}.pt".format(template_name)]
if MAIL_TEMPLATES_DIRECTORY != "":
# BBB this variable got patched outside this package.
# keep the old behavior of reading the patched directory template
templates = PageTemplateLoader(
MAIL_TEMPLATES_DIRECTORY, translate=ZPTTranslator(), debug=True
)
template = templates["{}.pt".format(template_name)]
else:
template = getMultiAdapter((context, getRequest()), name=template_name)
template_data["ascur"] = ascur
return template(**template_data)

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@

<head></head>

<body>
<body tal:define="
order options/order;
booking options/booking;
">
<h1 i18n:translate="order_mail_booking_cancelled_heading">
One of your bookings was cancelled
</h1>

<strong i18n:translate="order_mail_date">Date</strong>:
<tal:date replace="order['date']" />
${order/date}
<br />

<strong i18n:translate="order_mail_ordernumber">Ordernumber</strong>:
<tal:ordernumber replace="order['ordernumber']" />
${order/ordernumber}
<br />

<strong i18n:translate="order_mail_cancelled_item">Cancelled item</strong>:
<tal:cancelled_item replace="booking['title']" />
${booking/title}
<br />

<strong i18n:translate="order_mail_order_details">Order details</strong>:
<a href="${order['portal_url'] + '/@@showorder?ordernumber=' + order['ordernumber']}"
<a href="${order/portal_url}/@@showorder?ordernumber=${order/ordernumber}"
i18n:translate="order_mail_click_here">
Click here
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@

<head></head>

<body>
<body tal:define="
order options/order;
booking options/booking;
">
<h1 i18n:translate="order_mail_booking_reserved_to_ordered_heading">
Your reserved item is now available and our order is being processed
</h1>

<strong i18n:translate="order_mail_date">Date</strong>:
<tal:date replace="order['date']" />
${order/date}
<br />

<strong i18n:translate="order_mail_ordernumber">Ordernumber</strong>:
<tal:ordernumber replace="order['ordernumber']" />
${order/ordernumber}
<br />

<strong i18n:translate="order_mail_booked_item">Booked item</strong>:
<tal:cancelled_item replace="booking['title']" />
${booking/title}
<br />

<strong i18n:translate="order_mail_order_details">Order details</strong>:
<a href="${order['portal_url'] + '/@@showorder?ordernumber=' + order['ordernumber']}"
<a href="${order/portal_url}/@@showorder?ordernumber=${order/ordernumber}"
i18n:translate="order_mail_click_here">
Click here
</a>
Expand Down
34 changes: 34 additions & 0 deletions src/bda/plone/orders/mailnotifytemplates/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:zcml="http://namespaces.zope.org/zcml">

<browser:page
for="*"
name="booking_cancelled"
template="booking_cancelled.pt"
permission="zope2.View"
layer="..interfaces.IOrdersExtensionLayer" />

<browser:page
for="*"
name="booking_reserved_to_ordered"
template="booking_reserved_to_ordered.pt"
permission="zope2.View"
layer="..interfaces.IOrdersExtensionLayer" />

<browser:page
for="*"
name="order_success"
template="order_success.pt"
permission="zope2.View"
layer="..interfaces.IOrdersExtensionLayer" />

<browser:page
for="*"
name="stock_threshold_reached"
template="stock_threshold_reached.pt"
permission="zope2.View"
layer="..interfaces.IOrdersExtensionLayer" />

</configure>
Loading