Reference¶
pynotify.config¶
pynotify.dispatchers¶
pynotify.exceptions¶
pynotify.handlers¶
- class pynotify.handlers.BaseHandler[source]¶
Bases:
object
Base class for handling creation of notification(s). Its purpose is to process signal kwargs sent over a defined signal. There should be typically one handler (inherited from this class) for each signal. The handler must define inner class
Meta
with following supported attributes:signal
: Signal to which handler will be registeredallowed_senders
: Handler will be called only if signal was sent by allowed senderabstract
: If set to True, the handler will not be registered
- dispatcher_classes¶
An iterable of dispatcher classes that will be used to dispatch each notification.
- template_slug¶
Slug of an existing admin template to be used. If not defined, you must define
get_template_data()
method.
- get_dispatcher_classes()[source]¶
Returns iterable of dispatcher classes used to dispatch notification(s).
- get_extra_data()[source]¶
Returns a dictionary with extra data, the values must be JSON serializable.
Returns a list or dictionary of related objects in format {“name”: object}. Named related objects (i.e. those passed using a dictionary) can be referred in notification template.
pynotify.helpers¶
- class pynotify.helpers.DeletedRelatedObject[source]¶
Bases:
object
- Placeholder class that substitutes deleted related object and returns:
“[DELETED]” as its string representation
itself for any attribute accessed
- class pynotify.helpers.SecureRelatedObject(related_object)[source]¶
Bases:
object
Security proxy class allowing to access only string representation of the related object and a set of attributes defined in RELATED_OBJECTS_ALLOWED_ATTRS settings.
- pynotify.helpers.autoload()[source]¶
Attempts to load (import) notification handlers from modules defined in
PYNOTIFY_AUTOLOAD_MODULES
- pynotify.helpers.get_from_context(variable, context)[source]¶
Tries to find variable value in given context.
- Parameters
variable – Variable to look for. Template format is supported (e.g. “abc.def.ghi”).
context – Template context.
- Returns
Variable value or None if not found.
- pynotify.helpers.process_task(handler_class, serializer_class, signal_kwargs)[source]¶
Deserializes signal kwargs using the given serializer and calls given handler. This function is intended to be called from a Celery task.
- pynotify.helpers.receive(sender, **kwargs)[source]¶
Initiates processing of the signal by notification handlers through a receiver.
pynotify.models¶
- class pynotify.models.AdminNotificationTemplate(*args, **kwargs)[source]¶
Bases:
BaseTemplate
Represents a “template of a template”. This model is intended to be managed from administration, hence its name. It is identified by slug, which can be used for notification creation. However, this template is never used to directly render a notification, but instead is used to create NotificationTemplate with same values.
- slug¶
Template slug, with which this template can be referred to.
- is_active¶
Flag that switches on/off creating notifications from this template.
- is_locked¶
Flag that switches on/off this template editing (for admin purposes, requires admin-side support).
- send_push¶
Flag that switches on/off sending push notifications from this template. Currently, it has no effect on its own, but you can use it in your custom push notification solution.
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- class pynotify.models.BaseModel(*args, **kwargs)[source]¶
Bases:
SmartModel
Base class for models that outpus its verbose name and PK.
- class pynotify.models.BaseTemplate(*args, **kwargs)[source]¶
Bases:
BaseModel
Base abstract model for notification template.
- title¶
Title of the notification.
- text¶
Text of the notification.
- trigger_action¶
Arbitrary action performed when user triggers (i.e. clicks/taps) the notification.
- extra_fields¶
Can be used to store additional fields needed in particular use case.
- class pynotify.models.Notification(*args, **kwargs)[source]¶
Bases:
BaseModel
Represents the notification.
Attributes specified in
TEMPLATE_FIELDS
are also available here, as generated properties, that are evaluated at runtime and will return rendered field from the associated template. By default, the context used for rendering is filled with named related objects and extra data, so they can be referenced in the template by their name/key.- recipient¶
Recipient of the notification.
- template¶
Template used to render generated notification fields.
- is_read¶
Boolean flag indicating that recipitent has seen the notification.
- is_triggered¶
Boolean flag indicating that recipient has triggered the notification (e.g. clicked/tapped)
- extra_data¶
JSON serialized dictionary with extra data.
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- clean()[source]¶
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.
- property context¶
Returns context dictionary used for rendering the template.
Returns named related objects as a dictionary where key is name of the related object and value is the object itself. Related objects without name are skipped.
- class pynotify.models.NotificationMeta(name, bases, attrs)[source]¶
Bases:
SmartModelBase
,type
Creates property for each template field. The property returns rendered template.
- class pynotify.models.NotificationQuerySet(model=None, query=None, using=None, hints=None)[source]¶
Bases:
SmartQuerySet
- class pynotify.models.NotificationRelatedObject(*args, **kwargs)[source]¶
Bases:
BaseModel
Represents object related to a notification. This object can be then referenced in notification template fields by its name (if not None).
- name¶
String identificator of the object (for referencing in templates).
- notification¶
Related notification.
- content_object¶
The related object itself.
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- class pynotify.models.NotificationTemplate(*args, **kwargs)[source]¶
Bases:
BaseTemplate
Represents template that is used for rendering notification fields. Each field specified in
TEMPLATE_FIELDS
is a template string, that can be rendered using therender
method.- admin_template¶
Reference to admin template that was used to create this notification template.
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
pynotify.notify¶
- class pynotify.notify.NotifyHandler[source]¶
Bases:
BaseHandler
Notification handler for the
notify
method.- get_dispatcher_classes()[source]¶
Returns iterable of dispatcher classes used to dispatch notification(s).
- get_extra_data()[source]¶
Returns a dictionary with extra data, the values must be JSON serializable.
Returns a list or dictionary of related objects in format {“name”: object}. Named related objects (i.e. those passed using a dictionary) can be referred in notification template.
pynotify.receivers¶
- class pynotify.receivers.AsynchronousReceiver(handler_class)[source]¶
Bases:
BaseReceiver
Signal receiver that calls notification handler asynchronously via Celery.
- class pynotify.receivers.BaseReceiver(handler_class)[source]¶
Bases:
object
Base class for receiving signals. Its purpose is to pass signal kwargs to the notification handler.
- class pynotify.receivers.SynchronousReceiver(handler_class)[source]¶
Bases:
BaseReceiver
Signal receiver that calls notification handler synchronously.
pynotify.serializers¶
- class pynotify.serializers.BaseSerializer[source]¶
Bases:
object
Base class for serializing/deserializing signal kwargs. Its puprose is to transform signal kwargs to be directly JSON serializable (for compatible types, see https://docs.python.org/3/library/json.html#py-to-json-table).