Skip to main content

Introduction

The package allows you to notify users of actions or action requests for site content and actions.

Installation

Download the package from GitHub and extract into your src directory. Add ‘collective.notifications’ to your eggs and zcml slugs in buildout. Include the location (src/collective.notifications) in development slugs too. Run buildout

In Site Setup -> Add-ons, activate Notifications. Once it is installed you will see “Notifications” under Add-on Configuration. This is where you can see and manage site notifications. There is also a link here to a form that allows admins to send notifications.

Sending Notifications

To send notifications from code, use NotificationRequestedEvent. Send the event notification from the place in your code where it is required, using code similar to this:

from zope.event import notify
from collective.notification.interfaces import NotificationRequestedEvent
notify(NotificationRequestedEvent(context,
                                  note,
                                  recipients,
                                  user=user_id,
                                  url=action_url,
                                  external='email',
                                  email_body=email_body,
                                  email_subject=email_subject,
                                  email_content_type=content_type,
                                  first_read=False))

The context is the affected object. note is a plain text string with the description of the action that is being notified or needs to be performed; recipients is a list of user ids of all the users that will be notified, it allows the use of group ids with the prefix “group”, so for example [‘group:Reviewers’, ‘group:Staff’, ‘jsmith’, ‘jdoe’] would send the notification to all users of the groups reviewers and staff, as well as to individual users jsmith and jdoe. The special group “Members” will notify all portal users.

The last seven parameters are optional: user can be the userid of the user associated with the notification. This is just in case we need a different user than the currently logged in user, which is the default. url will be used as a site action if provided, otherwise the context url will be used. external refers to external notification services (see below). Currently, the only service included is ‘email’. The parameter can be a list, in which case the notification is sent using all the listed services. Default is None, so no external notifications will be sent if this parameter is omitted. Finally, first_read, if True, marks the notification as read for all recipients after one user reads it. This can be used to send a notification to a group where multiple users can take action, but can safely ignore the notification once someone reads it. Default is False. email_body is text for the body of the email sent by the ‘email’ external service. note will be used if email_body is not set. email_body should be either html or plain text. email_content_type should be ‘text/html’ if email_body is html. email_subject text for the subject of the email sent by the ‘email’ external service.

External Notification Services

Collective.notifications allowseasy integration with external notification services. Use the IExternalNotificationService interface for this. If a class implements this interface and it has a send method, it can be used as a service and included in the external parameter when sending a notification.

Example:

from zope.interface import implements
from collective.notification.interfaces import IExternalNotificationService

class TwitterNotifier(object):
    implements(IExternalNotificationService)

    def send(self, notification):
        # send the tweet
        ...

This requires configuring the service as un utility in configure.zcml:

<utility
  provides="collective.notifications.interfaces.IExternalNotificationService"
  factory=".external.TwitterNotifier"
  name="twitter"
/>

Async and Celery

Notifications attempts to use plone.app.async to perform the notifications, but if that fails it will finish the task directly. The advantage of this is to allow an individual ‘worker’ client to run Async and handle all of these request. If there is a lot of activity it will not get backed up. Async queues the job up and handles it as it can while the users request finishes and moves on avoiding sacrifices in performance. Refer to the collective.async pypi page for instructions on setting it up if you use it. Async is NOT required for Notifications to work, however it is advised, especially for high traffic sites.

Note

For inserting the number of pending notifications, the “toolbar.pt” template from plone.app.layout was overridden using z3c.jbot. Keep this in mind if your project has its own modifications for this template.

Metadata

Release files for collective.notifications 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for collective.notifications 1.2
File Size Uploaded
collective.notifications-1.2.zip 32.6 kB Details

Release files / collective.notifications-1.2.zip

Download URL collective.notifications-1.2.zip
Size 32.6 kB
Tags Source
SHA-256 checksum
How to use checksums
437579301b53a25c25ade990c4aeadc0be1d264a5fcf908e9c439403a6401eba
BLAKE2b-256 checksum
How to use checksums
6104570150dfb440e2f9df913e477c561c8c0c3677c4ad077caaa385d197ee05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release history Release notifications | RSS feed

This release

1.2 This release

1 release file

1.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page