Email async notifications with celery.
Project description
Async notifications
=====================
Email notification with celery and administrative view for send email with delay e.g daily
Features
---------
- Celery integration
- Administrative view
- Enqueued mail system and instantly send
- Problems notification
- User filter email
- Template system with template context
- Send to User, Group or external email
- Django cms integration (djcms_async_notifications) and standalone.
- Custom text area widget support
- Allow send group mail list if it's defined.
Installation
=============
#. Install from pip
.. code:: bash
$ pip install async_notifications
#. Insert *async_notifications* and *ajax_select* in your settings *INSTALLED_APPS*
#. Add ajax_select urls in urls.py
.. code:: python
from ajax_select import urls as ajax_select_urls
urlpatterns = [
...
url(r'^ajax_select/', include(ajax_select_urls)),
]
#. It's really important set *CELERY_MODULE* pointing to your project celery file, because it's needed for assing task to the current project, and configure some default celery options
.. code:: python
from __future__ import absolute_import
CELERY_MODULE = "demo.celery"
CELERY_TIMEZONE = TIME_ZONE
CELERY_ACCEPT_CONTENT = ['pickle', 'json']
from celery.schedules import crontab
CELERYBEAT_SCHEDULE = {
# execute 12:30 pm
'send_daily_emails': {
'task': 'async_notifications.tasks.send_daily',
'schedule': crontab(minute=30, hour=0),
},
}
#. Configure your email settings, e.g for development
.. code:: python
DEFAULT_FROM_EMAIL="mail@example.com"
EMAIL_HOST="localhost"
EMAIL_PORT="1025"
#. Run migrations
.. code:: bash
$ python manage.py migrate
Runing the project
===================
You need to run 3 subsystems for run this app so you need 3 xterm, for this explanation I will use the demo project
1. Run smtp debug client
.. code:: bash
$ python -m smtpd -n -c DebuggingServer localhost:1025
2. Run celery, if you aren't setup celery yet see `celery documentation <http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html>`_.
.. code:: bash
$ celery -A demo worker -l info -B
3. Run django
.. code:: bash
$ python manage.py runserver
Usage
=========
Report your context template
.. code:: python
from async_notifications.register import update_template_context
context = [
('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 have `send_email_from_template`
Send an email :)
.. code:: python
send_email_from_template(code, recipient,
context={},
enqueued=True,
user=None,
upfile=None)
Params description:
- `recipient` is a list of emails
- `code` is the same code register in update_template_context
- `enqueued` if **False** send the email immediately else enqueued to be sended when send email task run.
- `user` user how send email
- `upfile` attached file in email
Other optional options
========================
Adding context dummy object
----------------------------
When 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}}
from async_notifications.register import update_template_context, DummyContextObject
context = [
('myobj', 'Field description'),
...
]
message = render_to_string('some/template.html',
context={
'myobj': DummyContextObject('myobj')
}
)
update_template_context("yourcode", 'your email subject', context, message=message )
Django cms integration
-------------------------
This configuration could help you to integrate with Django CMS.
include in your `INSTALLED_APPS`:
.. code:: python
INSTALLED_APPS = [
...
'async_notifications',
'async_notifications.djcms_async_notifications',
]
Configure how models and field async_notifications will use, ej. aldryn_people
.. code:: python
ASYNC_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'}
.. note:: Django auth is used by default
cmsplugin-contact-plus
-------------------------
CONTACT_PLUS_SEND_METHOD = 'async_notifications.djcms_async_notifications.contact_plus.send_email'
ASYNC_NOTIFICATION_CONTACT_PLUS_EMAIL = 'email'
.. note::
This requires special cmsplugin-contact-plus version, we send a PRs, but is not merged yet.
Default text area widget
--------------------------
For example using ckeditor widget
ASYNC_NOTIFICATION_TEXT_AREA_WIDGET = 'ckeditor.widgets.CKEditorWidget'
.. note::
See how to configure `CKEditor <https://github.com/django-ckeditor/django-ckeditor>`_ .
=====================
Email notification with celery and administrative view for send email with delay e.g daily
Features
---------
- Celery integration
- Administrative view
- Enqueued mail system and instantly send
- Problems notification
- User filter email
- Template system with template context
- Send to User, Group or external email
- Django cms integration (djcms_async_notifications) and standalone.
- Custom text area widget support
- Allow send group mail list if it's defined.
Installation
=============
#. Install from pip
.. code:: bash
$ pip install async_notifications
#. Insert *async_notifications* and *ajax_select* in your settings *INSTALLED_APPS*
#. Add ajax_select urls in urls.py
.. code:: python
from ajax_select import urls as ajax_select_urls
urlpatterns = [
...
url(r'^ajax_select/', include(ajax_select_urls)),
]
#. It's really important set *CELERY_MODULE* pointing to your project celery file, because it's needed for assing task to the current project, and configure some default celery options
.. code:: python
from __future__ import absolute_import
CELERY_MODULE = "demo.celery"
CELERY_TIMEZONE = TIME_ZONE
CELERY_ACCEPT_CONTENT = ['pickle', 'json']
from celery.schedules import crontab
CELERYBEAT_SCHEDULE = {
# execute 12:30 pm
'send_daily_emails': {
'task': 'async_notifications.tasks.send_daily',
'schedule': crontab(minute=30, hour=0),
},
}
#. Configure your email settings, e.g for development
.. code:: python
DEFAULT_FROM_EMAIL="mail@example.com"
EMAIL_HOST="localhost"
EMAIL_PORT="1025"
#. Run migrations
.. code:: bash
$ python manage.py migrate
Runing the project
===================
You need to run 3 subsystems for run this app so you need 3 xterm, for this explanation I will use the demo project
1. Run smtp debug client
.. code:: bash
$ python -m smtpd -n -c DebuggingServer localhost:1025
2. Run celery, if you aren't setup celery yet see `celery documentation <http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html>`_.
.. code:: bash
$ celery -A demo worker -l info -B
3. Run django
.. code:: bash
$ python manage.py runserver
Usage
=========
Report your context template
.. code:: python
from async_notifications.register import update_template_context
context = [
('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 have `send_email_from_template`
Send an email :)
.. code:: python
send_email_from_template(code, recipient,
context={},
enqueued=True,
user=None,
upfile=None)
Params description:
- `recipient` is a list of emails
- `code` is the same code register in update_template_context
- `enqueued` if **False** send the email immediately else enqueued to be sended when send email task run.
- `user` user how send email
- `upfile` attached file in email
Other optional options
========================
Adding context dummy object
----------------------------
When 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}}
from async_notifications.register import update_template_context, DummyContextObject
context = [
('myobj', 'Field description'),
...
]
message = render_to_string('some/template.html',
context={
'myobj': DummyContextObject('myobj')
}
)
update_template_context("yourcode", 'your email subject', context, message=message )
Django cms integration
-------------------------
This configuration could help you to integrate with Django CMS.
include in your `INSTALLED_APPS`:
.. code:: python
INSTALLED_APPS = [
...
'async_notifications',
'async_notifications.djcms_async_notifications',
]
Configure how models and field async_notifications will use, ej. aldryn_people
.. code:: python
ASYNC_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'}
.. note:: Django auth is used by default
cmsplugin-contact-plus
-------------------------
CONTACT_PLUS_SEND_METHOD = 'async_notifications.djcms_async_notifications.contact_plus.send_email'
ASYNC_NOTIFICATION_CONTACT_PLUS_EMAIL = 'email'
.. note::
This requires special cmsplugin-contact-plus version, we send a PRs, but is not merged yet.
Default text area widget
--------------------------
For example using ckeditor widget
ASYNC_NOTIFICATION_TEXT_AREA_WIDGET = 'ckeditor.widgets.CKEditorWidget'
.. note::
See how to configure `CKEditor <https://github.com/django-ckeditor/django-ckeditor>`_ .
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
async_notifications-0.1.8.tar.gz
(27.6 kB
view details)
File details
Details for the file async_notifications-0.1.8.tar.gz
.
File metadata
- Download URL: async_notifications-0.1.8.tar.gz
- Upload date:
- Size: 27.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41f52eb37e230bf5f623b10cc433434ac07f0eac67aafa7dc59c62f58c57b8c4 |
|
MD5 | d88cddb3a945405e6e80eb3ee7a1bce7 |
|
BLAKE2b-256 | 21cfa4bf39be51dd571f8be16952e5e1838897339af016f1efa3c2eddbb96ae5 |