A Django package for email template editing
Project description
Django e-mail templates!
Many projects have a well defined set of events that trigger an outgoing e-mail, and the sensible thing is to template these out.
However, doing code updates and deployments for small template tweaks are a bit cumbersome and annoying.
This project aims to solve that - define the types of templates in the code, and edit the actual templates in the front-end. Templates are validated on syntax and required/optional content.
This project also aims to solve the HTML email template problems that you can have when supporting all email clients. This was also used by foundation for email. Foundation for email is a good way to build your initial email template on development mode. It will generate a separate html file and css file.
For e-mail sending and logging, we recommend using a solution such as Django Yubin.
This is only tested on a postgres database.
Supported are:
python 3.10, 3.11, 3.12
Django 3.2, 4.2
PostgreSQL
Warning
This project is currently in development and not stable.
Installation
Install with pip:
pip install mail_editor
Add ‘mail_editor’ to the installed apps:
# settings.py
INSTALLED_APPS = [
...
'mail_editor',
'ckeditor',
...
]
Add the urls:
# urls.py
url(r'^mail-editor/', include('mail_editor.urls', namespace='mail_editor')),
Using the template
There are 2 templates that you can use.
The _base.html, this template can not be edited by the user. This will only be rendered when the email is send.
The _outer_table.html, this template can be edited by the user and will be loaded in the editor in the admin. This template will be saved in the database with the modifications.
You can use the templates in some different ways. The shortest way is:
from mail_editor.helpers import find_template
def email_stuff():
template = find_template('activation')
context = {
'name': 'Test Person',
'site_name': 'This site',
'activation_link': 'https://github.com/maykinmedia/mail-editor',
}
template.send_email('test@example.com', context)
Settings
The following settings are an example:
MAIL_EDITOR_CONF = {
'activation': {
'name': gettext_noop('Activation Email'),
'description': gettext_noop('This email is used when people need to activate their account.'),
'subject_default': 'Activeer uw account voor {{site_name}}',
'body_default': """
<h1>Hallo {{ name }},</h1>
<p>Welkom! Je hebt je geregistreerd voor een {{ site_name }} account.</p>
<p>{{ activation_link }}</p>
""",
'subject': [{
'name': 'site_name',
'description': gettext_noop('This is the name of the site. From the sites'),
'example': gettext_noop('Example site'),
}],
'body': [{
'name': 'name',
'description': gettext_noop('This is the name of the user'),
'example': gettext_noop('Jane Doe'),
}, {
'name': 'site_name',
'description': gettext_noop('This is the name of the site. From the sites'),
'example': gettext_noop('Example site'),
}, {
'name': 'activation_link',
'description': gettext_noop('This is the link to activate their account.'),
'example': gettext_noop('/'),
}]
},
...
}
These settings are usefull to add:
# These settings make sure that CKEDITOR does not strip any html tags. like <center></center>
CKEDITOR_CONFIGS = {
'mail_editor': {
'allowedContent': True,
'contentsCss': ['/static/css/email.css'], # Enter the css file used to style the email.
'height': 600, # This is optional
'entities': False, # This is added because CKEDITOR escapes the ' when you do an if statement
}
}
You can set template variables to all of the mail templates in the following fashion.
# static dictionary
MAIL_EDITOR_BASE_CONTEXT = {
'url': 'http://www.maykinmedia.nl',
}
# import path to callable that returns a dictionary
MAIL_EDITOR_DYNAMIC_CONTEXT = "dotted.path.to.callable"
Installation
Install with pip:
pip install mail_editor
Local development
To install and develop the library locally, use:
.. code-block:: bash
pip install -e .[tests,coverage,release]
When running management commands via django-admin, make sure to add the root directory to the python path (or use python -m django <command>):
export PYTHONPATH=. DJANGO_SETTINGS_MODULE=testapp.settings
django-admin check
# or other commands like:
django-admin migrate
django-admin createsuperuser
django-admin runserver
# django-admin makemessages -l nl
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mail_editor-0.3.7.tar.gz
.
File metadata
- Download URL: mail_editor-0.3.7.tar.gz
- Upload date:
- Size: 107.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee905098b5e35bdf34ac534c705dfb6316b5ede50d343aab5e570f53ddc714c2 |
|
MD5 | 51a1d24b5fab722ed693acbeafd30e25 |
|
BLAKE2b-256 | b310440c6e621f167b54eb3785fefed949c80db3eed5b23df4cd05a0b3c8b677 |
File details
Details for the file mail_editor-0.3.7-py2.py3-none-any.whl
.
File metadata
- Download URL: mail_editor-0.3.7-py2.py3-none-any.whl
- Upload date:
- Size: 30.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9517e14030adc84d20a6dc417c9d8ac8fc9190b004fd5b0e1c58d619e958874f |
|
MD5 | 0925352a19c492b791bbe2dbe07ce229 |
|
BLAKE2b-256 | 6c1f6d0eb2fdb03a6fcac6cb439b37be753b923043d6f740acd85fbb3e152533 |