Package: django-transactional-notifications
Django notificationsInstallpipinstalldjango-transactional-notifications# settings.pyINSTALLED_APPS+=["txn_notifications"]DJANGO_NOTIFICATIONS={"email":{"enabled":True,}}FeaturesTemplate based notifications. You can use markdownEdit messages from django adminTemplate based messageRich html message format using markdownCustomizable and extensible handlerAdd your own handler for the services you useUser settings (allow/disallow notification by handler or category)Check message status (is_sent)Update message status (using callbacks)WrappersNotificationWrapperHandlersDjangoHandlerEmailHandler(generic)MailgunHandlerwithwebhooksSendgridTwilioHandlerwithcallbacksSMSWhatsappModelsNotification structureCategoryTemplateNotificationUser preferencesUserCategorySettingUserHandlerSettingSettingsOptional. Override the models.# settings.pyNOTIFICATIONS_CATEGORY_MODEL="notifications.Category"NOTIFICATIONS_TEMPLATE_MODEL="notifications.Template"NOTIFICATIONS_NOTIFICATION_MODEL="notifications.Notification"NOTIFICATIONS_USERHANDLERSETTING_MODEL="notifications.UserHandlerSetting"NOTIFICATIONS_USERCATEGORYSETTING_MODEL="notifications.UserCategorySetting"# your custom_module.pyimportswapperfromdjango.dbimportmodelsfromtxn_notifications.base.modelsimportAbstractNotificationclassMyNotification(AbstractNotification):# `get_model_name` is required if you want to override a ForeignKey# related to any override notification.model.template=models.ForeignKey(swapper.get_model_name("txn_notifications","Template"),on_delete=models.CASCADE,related_name="notifications",)classMeta(AbstractNotification.Meta):swappable=swapper.swappable_setting("txn_notifications","Notification")abstract=False# emailDEFAULT_FROM_EMAIL="Test <test@test.com>"EMAIL_BACKEND="django.core.mail.backends.console.EmailBackend"DJANGO_NOTIFICATIONS={"email":{"enabled":False,# user model attribute"recipient_attr":"email",# templates"html_template":"notifications/templates/email.html","txt_template":"notifications/templates/email.txt",},"twilio":{"enabled":False,"recipient_attr":None,# account settings"account_sid":None,"auth_token":None,"sms_sender":None,},}EmailsettingsYou can override it in the settings or in thedatapayload in the notification.Using configurations:DJANGO_NOTIFICATIONS={"email":{"enabled":False,"html_template":"notifications/templates/email.html","txt_template":"notifications/templates/email.txt","recipient_attr":"email",},}Using notification data:data={# tempalte data (created by the template)"title":"","body":"","url":"",# button url"url_msg":"",# button copy# template data (optional)"prehead":"",# optional"image":"url to the image",# optional"image_alt":"",# optional"intro":"",# optional (before body)"outro":"",# optional (after body)"footer":"",# optional (outside the box)# or you can chage the email template"txt_template":"path/to/template.txt","html_template":"path/to/template.html",# other options related to the email"bcc":[],"connection":None,"attachments":[],"headers":[],"alternatives":[],"cc":[],"reply_to":[]}Getting the recipient attrYou can chage therecipient_attrin the settings. This will try to get
the attribute from theUsermodel.If that attribute comes from another model, or it must be calculated by a
function, then you can override theget_reecipientfunction by extending
from theEmailHandleror any other handler inherit from it.fromtxn_notifications.handlers.emailimportEmailHandlerclassMyEmailHandler(EmailHandler):defget_recipient(self)->list:returnself.user.settings.any_other_attributeTemplatesIf you want to use your own templates ...Changehtml_templateandtxt_templatein the settings or in thedatapayload.Set the django template tags{{ title }},{{ body }}, etc.Remember to validate inline your html/css.Inliners:https://templates.mailchimp.com/resources/inline-css/Check/update message statusCallbacksnotifications/callbacks/{callback_id}/(mailgun)https://documentation.mailgun.com/en/latest/quickstart-events.html#eventshttps://www.mailgun.com/blog/product/a-guide-to-using-mailguns-webhooks/(twillio)https://www.twilio.com/docs/sms/tutorials/how-to-confirm-delivery-pythonTestingInstall pipenvpipinstallpipenvInstall dependenciespipenvinstall--devRun testspipenvrunpytest--cov=txn_notifications.Runing DjangoRun migrationspipenvrunpythonmanage.pymigrateCreate Super Userpipenvrunpythonmanage.pycreatesuperuserRun serverpipenvrunpythonmanage.pyrunserverOpen adminhttp://localhost:8000/admin/