Skip to main content

A Django package for email template editing

Project description

Version:
0.3.9

Build status Code quality checks black Coverage status

python-versions django-versions pypi-version

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.11, 3.12, 3.13

  • Django 4.2, 5.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

path('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

mail_editor-0.3.9.tar.gz (108.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mail_editor-0.3.9-py2.py3-none-any.whl (31.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file mail_editor-0.3.9.tar.gz.

File metadata

  • Download URL: mail_editor-0.3.9.tar.gz
  • Upload date:
  • Size: 108.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for mail_editor-0.3.9.tar.gz
Algorithm Hash digest
SHA256 d290d3633889ae135dc81eb9a3adb7b66d6fa485cd551d0b8c9cc98266ff3b96
MD5 9ef9a52e422b8170643ba389a57594a0
BLAKE2b-256 f42fc6d416a9947313fa7e9a7ebfc5827f1f0720760763293645966f455c3dfd

See more details on using hashes here.

Provenance

The following attestation bundles were made for mail_editor-0.3.9.tar.gz:

Publisher: ci.yml on maykinmedia/mail-editor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mail_editor-0.3.9-py2.py3-none-any.whl.

File metadata

  • Download URL: mail_editor-0.3.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 31.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for mail_editor-0.3.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 82fc8a984aab137eb40fbd716afbd425d537e950370b4dafe697890e8f6a5907
MD5 ac6c3d77ab7a23a1e29cacb75c8511a1
BLAKE2b-256 e5efd11d1139ad90cb1ffeb098d460503e679830dcd7f2a7ed079882a5fd5904

See more details on using hashes here.

Provenance

The following attestation bundles were made for mail_editor-0.3.9-py2.py3-none-any.whl:

Publisher: ci.yml on maykinmedia/mail-editor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page