Package: async-notifications
Async notificationsEmail notification with celery and administrative view for send email with delay e.g dailyFeaturesCelery integrationAdministrative viewEnqueued mail system and instantly sendProblems notificationUser filter emailTemplate system with template contextSend to User, Group or external emailDjango cms integration (djcms_async_notifications) and standalone.Custom text area widget supportAllow send group mail list if it’s defined.Newsletter with model context, preview and extra email configurationInstallationInstall from pip$pipinstallasync_notificationsAdd required apps in your settings **INSTALLED_APPS=[...'async_notifications']Add ajax_select urls in urls.pyfromdjango.conf.urlsimporturl,includeurlpatterns=[...url(r'^async_notifications/',include('async_notifications.urls')),]It’s really important setCELERY_MODULEpointing to your project celery file, because it’s needed for assing task to the current project, and configure some default celery options# settings.pyCELERY_MODULE="demo.celery"CELERY_TIMEZONE=TIME_ZONECELERY_ACCEPT_CONTENT=['json']Configure your email settings, e.g for developmentDEFAULT_FROM_EMAIL="mail@example.com"EMAIL_HOST="localhost"EMAIL_PORT="1025"# Copy celery app in your project folder from demo, and adjust the crontab execution# celery.pyapp.conf.CELERYBEAT_SCHEDULE={# execute 12:30 pm'send_daily_emails':{'task':'async_notifications.tasks.send_daily','schedule':crontab(minute=30,hour=0),},}Remember use  demo/__init__.py to update your projectfolder/__init__.py.Run migrations$pythonmanage.pymigrateRuning the projectYou need to run 3 subsystems for run this app so you need 3 xterm, for this explanation I will use the demo projectRun smtp debug client$python-msmtpd-n-cDebuggingServerlocalhost:1025Run celery, if you aren’t setup celery yet seecelery documentation.$celery-Ademoworker-linfo-BRun django$pythonmanage.pyrunserverUsageReport your context templatefromasync_notifications.registerimportupdate_template_contextcontext=[('fieldname','Field description'),('fieldname2','Field description'),...]update_template_context("yourcode",'your email subject',context)This automátically create a Email template if not found.Context is list of tuples with the fields available in the template context, this context is add in the same file
that havesend_email_from_templateUsing with django templatesupdate_template_context("yourcode",'your email subject',context,'templatepath.html',as_template=True)Send dict as context is now available, but remember that you can not repit keys in dict so use with precaution.Send an email :)send_email_from_template(code,recipient,context={},enqueued=True,user=None,upfile=None)Params description:recipientis a list of emailscodeis the same code register in update_template_contextenqueuedifFalsesend the email immediately else enqueued to be sent when send email task run.useruser how send emailupfileattached file in emailOther optional optionsAdding context dummy objectWhen you need to pass a default template message base on template, but you have not the template object
and also you need to write the object with django template sintaxis you can use DummyContextObject that
return always something like {{ myobj.attr1.objattr }}fromasync_notifications.registerimportupdate_template_context,DummyContextObjectcontext=[('myobj','Field description'),...]message=render_to_string('some/template.html',context={'myobj':DummyContextObject('myobj')})update_template_context("yourcode",'your email subject',context,message=message)Newsletter email extra configurationAs recomendation install django-markitup and markdown to generate preview templates using django template system and configureASYNC_NEWSLETTER_WIDGETto overwrite default text area editor in template newsletter.If you want to incorporate custom email sender you can configure withASYNC_NEWSLETTER_SEVER_CONFIGSASYNC_NEWSLETTER_SEVER_CONFIGS={'host':'localhost','port':'1025','fail_silently':False,'backend':None,'from':'From user <user@example.com>''username':'my_username','password':'my_password','use_tls':True}Newsletter setupIn your app edit at the end of admin.py to register your modelregister_model('app.model_label',modelclass,prefix='prefix used to include in template')register_news_basemodel('app.model_label',Title,classmanager)To create a new manager you need to create a class likefromasync_notifications.interfacesimportNewsLetterInterfaceclassMembershipManager(NewsLetterInterface):name=nameusedtoincludeintemplatemodel=Modelform=FilterformclassTake a look to NewsLetterInterface to know what methods you need to overwriteDjango cms integrationThis configuration could help you to integrate with Django CMS.include in yourINSTALLED_APPS:INSTALLED_APPS=[...'async_notifications','async_notifications.djcms_async_notifications',]Configure how models and field async_notifications will use, ej. aldryn_peopleASYNC_NOTIFICATION_GROUP='aldryn_people.Group'ASYNC_NOTIFICATION_GROUP_LOOKUP_FIELDS={'order_by':'translations__name','email':'email','group_lookup':'translations__name','display':'name','filter':['translations__name__icontains']}ASYNC_NOTIFICATION_USER='aldryn_people.Person'ASYNC_NOTIFICATION_USER_LOOKUP_FIELDS={'order_by':'translations__name','display':'name','filter':['user__first_name__icontains','user__last_name__icontains','translations__name__icontains'],'group_lookup':'groups__translations__name'}NoteDjango auth is used by defaultcmsplugin-contact-plusCONTACT_PLUS_SEND_METHOD = ‘async_notifications.djcms_async_notifications.contact_plus.send_email’
ASYNC_NOTIFICATION_CONTACT_PLUS_EMAIL = ‘email’NoteThis requires special cmsplugin-contact-plus version, we send a PRs, but is not merged yet.Default text area widgetFor example using ckeditor widgetASYNC_NOTIFICATION_TEXT_AREA_WIDGET = ‘ckeditor.widgets.CKEditorWidget’NoteSee how to configureCKEditor.Extra settings configurationASYNC_NOTIFICATION_MAX_PER_MAIL   default 40 mails per emailASYNC_BCC  include always email in BCC comma separed email (without spaces)ASYNC_SEND_ONLY_EMAIL  for testing send all email to this addressASYNC_SMTP_DEBUG  configure smtp debug for logsASYNC_TEMPLATES_NOTIFICATION   path for save templates created in emails