Skip to content

Commit 2f04ee3

Browse files
pandafynemesifier
authored andcommitted
[change!] Dropped support for OPENWISP_EMAIL_TEMPLATE setting #482
Updated docs to suggest overriding the template. Closes #482
1 parent cfbd63e commit 2f04ee3

File tree

4 files changed

+40
-52
lines changed

4 files changed

+40
-52
lines changed

docs/developer/admin-theme.rst

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,12 @@ Sending emails
218218
``openwisp_utils.admin_theme.email.send_email``
219219
+++++++++++++++++++++++++++++++++++++++++++++++
220220

221-
This function allows sending email in both plain text and HTML version
222-
(using the template and logo that can be customized using
223-
:ref:`OPENWISP_EMAIL_TEMPLATE <openwisp_email_template>` and
224-
:ref:`OPENWISP_EMAIL_LOGO <openwisp_email_logo>` respectively).
221+
This function enables sending emails in both plain text and HTML formats.
222+
The HTML version uses a customizable template and logo.
223+
224+
You can set the logo using the :ref:`OPENWISP_EMAIL_LOGO
225+
<openwisp_email_logo>` setting. To override the default template, see
226+
:ref:`Customizing Email Templates <utils_send_email>`.
225227

226228
In case the HTML version if not needed it may be disabled by setting
227229
:ref:`OPENWISP_HTML_EMAIL <openwisp_html_email>` to ``False``.
@@ -242,7 +244,7 @@ In case the HTML version if not needed it may be disabled by setting
242244
``call_to_action_text`` and ``call_to_action_url`` can be passed to show a call to action
243245
button. Similarly, ``footer`` can be passed to add a footer.
244246
``html_body_template`` **(optional, str)** The path to the template used for generating the HTML version. By
245-
default, it uses the template specified in :ref:`openwisp_email_template`.
247+
default, it uses ``openwisp_utils/email_template.html``.
246248
``**kwargs`` Any additional keyword arguments (e.g. ``attachments``, ``headers``, etc.) are passed
247249
directly to the `django.core.mail.EmailMultiAlternatives
248250
<https://docs.djangoproject.com/en/4.1/topics/email/#sending-alternative-content-types>`_.
@@ -252,3 +254,35 @@ In case the HTML version if not needed it may be disabled by setting
252254

253255
Data passed in body should be validated and user supplied data should
254256
not be sent directly to the function.
257+
258+
Customizing Email Templates
259+
+++++++++++++++++++++++++++
260+
261+
To customize the email templates used by the :ref:`utils_send_email`
262+
function, you can override the ``openwisp_utils/email_template.html``
263+
template in your Django project. Create a template with the same path
264+
(``openwisp_utils/email_template.html``) in your project's template
265+
directory to override the default template.
266+
267+
It is recommended to extend the default email template as shown below:
268+
269+
.. code-block:: django
270+
271+
{% extends 'openwisp_utils/email_template.html' %}
272+
{% block styles %}
273+
{{ block.super }}
274+
<style>
275+
.body {
276+
height: 100%;
277+
background: linear-gradient(to bottom, #8ccbbe 50%, #3797a4 50%);
278+
background-repeat: no-repeat;
279+
background-attachment: fixed;
280+
padding: 50px;
281+
}
282+
</style>
283+
{% endblock styles %}
284+
285+
Similarly, you can customize the HTML of the template by overriding the
286+
``body`` block. See `email_template.html
287+
<https://github.com/openwisp/openwisp-utils/blob/master/openwisp_utils/admin_theme/templates/openwisp_utils/email_template.html>`_
288+
for reference implementation.

docs/user/settings.rst

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -205,46 +205,6 @@ default ``True``
205205
If ``True``, an HTML themed version of the email can be sent using the
206206
:ref:`send_email <utils_send_email>` function.
207207

208-
.. _openwisp_email_template:
209-
210-
``OPENWISP_EMAIL_TEMPLATE``
211-
---------------------------
212-
213-
======= ======================================
214-
type ``str``
215-
default ``openwisp_utils/email_template.html``
216-
======= ======================================
217-
218-
This setting allows to change the django template used for sending emails
219-
with the :ref:`send_email <utils_send_email>` function. It is recommended
220-
to extend the default email template as in the example below.
221-
222-
.. code-block:: django
223-
224-
{% extends 'openwisp_utils/email_template.html' %}
225-
{% block styles %}
226-
{{ block.super }}
227-
<style>
228-
.background {
229-
height: 100%;
230-
background: linear-gradient(to bottom, #8ccbbe 50%, #3797a4 50%);
231-
background-repeat: no-repeat;
232-
background-attachment: fixed;
233-
padding: 50px;
234-
}
235-
236-
.mail-header {
237-
background-color: #3797a4;
238-
color: white;
239-
}
240-
</style>
241-
{% endblock styles %}
242-
243-
Similarly, you can customize the HTML of the template by overriding the
244-
``body`` block. See `email_template.html
245-
<https://github.com/openwisp/openwisp-utils/blob/master/openwisp_utils/admin_theme/templates/openwisp_utils/email_template.html>`_
246-
for reference implementation.
247-
248208
.. _openwisp_email_logo:
249209

250210
``OPENWISP_EMAIL_LOGO``

openwisp_utils/admin_theme/email.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def send_email(
1818
body_html,
1919
recipients,
2020
extra_context=None,
21-
html_email_template=app_settings.OPENWISP_EMAIL_TEMPLATE,
21+
html_email_template="openwisp_utils/email_template.html",
2222
**kwargs,
2323
):
2424
extra_context = extra_context or {}

openwisp_utils/admin_theme/settings.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
OPENWISP_ADMIN_THEME_JS = getattr(settings, "OPENWISP_ADMIN_THEME_JS", [])
1111
ADMIN_DASHBOARD_ENABLED = getattr(settings, "OPENWISP_ADMIN_DASHBOARD_ENABLED", True)
1212

13-
OPENWISP_EMAIL_TEMPLATE = getattr(
14-
settings,
15-
"OPENWISP_EMAIL_TEMPLATE",
16-
"openwisp_utils/email_template.html",
17-
)
18-
1913
OPENWISP_EMAIL_LOGO = getattr(
2014
settings,
2115
"OPENWISP_EMAIL_LOGO",

0 commit comments

Comments
 (0)