跳转到主要内容

Django邮件模板编辑器

项目描述

Coverage Code Climate

Django电子邮件模板!

许多项目都有明确定义的一系列事件,这些事件会触发发送电子邮件,因此合理的是将这些事件模板化。

然而,对代码更新和部署进行小的模板调整既繁琐又令人烦恼。

该项目旨在解决此问题 - 在代码中定义模板类型,并在前端编辑实际模板。模板在语法和必需/可选内容上都会进行验证。

本项目旨在解决在支持所有电子邮件客户端时可能遇到的HTML电子邮件模板问题。这也被电子邮件基金会所使用。电子邮件基金会是一个在开发模式下构建初始电子邮件模板的好方法。它将生成单独的HTML文件和CSS文件。

对于电子邮件发送和记录,我们推荐使用例如Django Yubin这样的解决方案。

此项目仅在PostgreSQL数据库上进行了测试。

支持如下

  • python 3.10, 3.11, 3.12

  • Django 3.2, 4.2

  • PostgreSQL

警告

本项目目前处于开发阶段,尚不稳定。

安装

使用pip安装

pip install mail_editor

‘mail_editor’添加到已安装的应用程序

# settings.py

INSTALLED_APPS = [
    ...
    'mail_editor',
    'ckeditor',
    ...
]

添加URL

# urls.py

url(r'^mail-editor/', include('mail_editor.urls', namespace='mail_editor')),

使用模板

您可以使用以下两个模板。

_base.html,此模板不能由用户编辑。它仅在发送电子邮件时才会渲染。

_outer_table.html,此模板可以由用户编辑,并在管理员中的编辑器中加载。此模板的修改将保存在数据库中。

您可以使用模板以不同的方式。最简单的方式是

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)

设置

以下设置是一个示例

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 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
    }
}

您可以使用以下方式设置所有邮件模板的模板变量。

# 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"

安装

使用pip安装

pip install mail_editor

本地开发

要本地安装和开发库,请使用以下命令

.. code-block:: bash

pip install -e .[tests,coverage,release]

当通过django-admin运行管理命令时,请确保将根目录添加到python路径中(或使用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

项目详情


下载文件

下载适用于您的平台文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

mail_editor-0.3.7.tar.gz (107.4 kB 查看哈希)

上传时间:

构建分布

mail_editor-0.3.7-py2.py3-none-any.whl (30.7 kB 查看哈希)

上传时间: Python 2 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面