跳转到主要内容

Django包,用于处理通知发送

项目描述

UNICEF通知

通知是一个提供通知发送处理的库。

安装

pip install unicef-notification

设置

将unicef_notification添加到settings中的INSTALLED_APPS

INSTALLED_APPS = [
    ...
    'post_office',
    'unicef_notification',
]

将POST_OFFICE配置添加到settings

POST_OFFICE = {
    'DEFAULT_PRIORITY': 'now',
    'BACKENDS': {
        'default': 'djcelery_email.backends.CeleryEmailBackend'
        }
}

通过添加EmailTemplateLoader并将APP_DIRS标记为False来更新settings中的TEMPLATES

TEMPLATES = [
    ...
    'APP_DIRS': False,  # False because we set loaders manually below
    'OPTIONS': {
    'loaders': [
        'django.template.loaders.app_directories.Loader',
        'unicef_notification.loaders.EmailTemplateLoader',
    ],
    ...
    ]

可选

如果您想覆盖要使用的通知模板目录

UNICEF_NOTIFICATION_TEMPLATE_DIR = 'notifications'

这是通知模板放置在您的应用程序中的目录。这些模板通过upload_notifications管理命令加载。

如果您想覆盖电子邮件模板前缀

UNICEF_NOTIFICATION_EMAIL_TEMPLATE_PREFIX = 'email-templates/'

用法

从设置中在定义的UNICEF_NOTIFICATION_TEMPLATE_DIR中创建通知模板

name = "<unique name for notification">
defaults = {
    "description": "Sample notification",
    "subject": "Subject of notification",
    "content": "Content of notification",
    "html_content": "Notificaton content in HTML format",
}

更新通知

python manage.py update_notifications

使用模板发送通知

from unicef_notification.utils import send_notification_with_template

context = {}
send_notification_with_template(
    ["to@example.com"],
    "<name-of-template>",
    context,
)

不使用模板发送通知

from unicef_notification.utils import send_notification

send_notification(
    ["to@example.com"],
    subject="Subject of notification",
    content="Content of notification",
    html_content="Notification content in HTML format",
)

贡献

环境设置

要安装必要的库

$ make install

编码规范

有关编码规范的详细信息,请参阅PEP 8 Python代码风格指南

对代码进行检查以确保代码符合规范

$ make lint

测试

测试非常重要,测试文件位于 tests/ 目录中,可以使用以下命令运行:

$ make test

覆盖率报告可在 build/coverage 目录中查看,可以使用以下命令生成:

项目详情


下载文件

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

源代码分发

unicef_notification-1.4.1.tar.gz (7.9 kB 查看哈希值)

上传时间 源代码

构建分发

unicef_notification-1.4.1-py2.py3-none-any.whl (11.3 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下机构支持

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