Newsletter plugin¶
Plugin for Django CMS QE providing newsletter. It allows users to subscribe (simply add email to database) and also possibility to sync with external sources like MailChimp.
Usage¶
Add plugin from section Generic called Newsletter subscription form.
To synchronize emails with MailChimp, generate a api_key on MailChimp and set it with MailChimp username (which you can find or set in profile settings) in admin interface in Сonstance. Then you can synchronize mailing lists in list of mailing lists in admin interface and use those lists in your plugin.
API¶
Django CMS¶
Newsletter Django-CMS plugin. Allow add the form with subscriptions on a page.
alias of
django.forms.widgets.NewsletterPluginForm
Configuration model for newsletter plugin. Allows to set: * Title * Mail lists on mailchimp to which subscribers will be added * Show or hide full name * Require full name or not
Parameters: - id (AutoField) –
- path (CharField) –
- depth (PositiveIntegerField) –
- numchild (PositiveIntegerField) –
- placeholder_id (ForeignKey to
Placeholder
) – - parent_id (ForeignKey to
CMSPlugin
) – - position (PositiveSmallIntegerField) –
- language (CharField) –
- plugin_type (CharField) –
- creation_date (DateTimeField) –
- changed_date (DateTimeField) –
- cmsplugin_ptr_id (OneToOneField to
CMSPlugin
) – - title (CharField) – The title of subscribes that will be shown to users
- fullname_show (BooleanField) –
- fullname_require (BooleanField) –
- mailing_lists (ManyToManyField) –
Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
Models¶
Mailing list model which also synchronize with external services like Mailchimp. If
external_id
is not set then subscriber is not synchronized.Parameters: - id (BigAutoField) –
- name (CharField) –
- external_service (PositiveSmallIntegerField) –
- external_id (CharField) –
Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
Subscriber model which also synchronize with external services like Mailchimp. If
external_id
is not set then subscriber is not synchronized.Parameters: - id (BigAutoField) –
- mailing_list_id (ForeignKey to
MailingList
) – - email (EmailField) –
- first_name (CharField) –
- last_name (CharField) –
- external_id (CharField) –
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
Called before save to create task to sync action with external service.
Called before delete to create task to sync action with external service.
Item for task queue for subscribing and unsubscribing members on the external service like Mailchimp. The queue can is processed by
cms-qe-newsletter-sync
command.Parameters: - id (BigAutoField) –
- mailing_list_id (ForeignKey to
MailingList
) – - email (EmailField) –
- first_name (CharField) –
- last_name (CharField) –
- external_id (CharField) –
- type (PositiveSmallIntegerField) –
- created (DateTimeField) –
- attempts (PositiveSmallIntegerField) –
- last_error (TextField) –
Checks whether task should be tried to process. With less attempts it tries more often, with more attempts it waits more time to not overwhelm resources.
Views¶
Download mailing lists from external services like Mailchimp.
Used in administration in custom button “Synchronize mailing list from external sources”.
Manage¶
Command processes the queue to subscribing and unsubscribing on the external services. Usage of command with
manage.py
:python -m manage.py cms_qe_newsletter_sync
The actual logic of the command. Subclasses must implement this method.
Services¶
Download mailing lists from external services like Mailchimp.
Processing task returning tuple of status (
True
for success,False
for some failure andNone
for warnings) and message.
Processing tasks yielding same tuple as
sync_task()
function.
Mailchimp¶
Helper class to communicate with MailChimp.
Returns: List of lists with fields id
andname
.
Add a subscriber and return the id (subscriber_hash).
Remove a subscriber.