Models

class notify.models.Notification(*args, **kwargs)[source]

Notification Model for storing notifications. (Yeah, too obvious)

This model is pretty-much a replica of django-notifications’s model. The newly added fields just adds a feature to allow anonymous actors, targets and object.

Attributes:
recipient:The user who receives notification.
verb:Action performed by actor (not necessarily).
description:Option description for your notification.
actor_text:Anonymous actor who is not in content-type.
actor_url:Since the actor is not in content-type, a custom URL for it.

…Same for target and obj.

nf_type:
Each notification is different, they must be formatted
differently during HTML rendering. For this, each
notification gets to carry it own notification type.

This notification type will be used to search
the special template for the notification located at
notifications/includes/NF_TYPE.html of your
template directory.

The main reason to add this field is to save you
from the pain of writing if...elif...else blocks
in your template file just for handling how
notifications will get rendered.

With this, you can just save template for an individual
notification type and call the template-tag to render
all notifications for you without writing a single
if...elif...else block.

You’ll just need to do a
{% render_notifications using NOTIFICATION_OBJ %}
and you’ll get your notifications rendered.

By default, every nf_type is set to default.
Extra:JSONField, holds other optional data you want the notification to carry in JSON format.
Deleted:Useful when you want to soft delete your notifications.
actor

Property to return actor object/text to keep things DRY.

Returns:Actor object or Text or None.
actor_url

Property to return permalink of the actor. Uses get_absolute_url().

If get_absolute_url() method fails, it tries to grab URL from actor_url_text, if it fails again, returns a “#”.

Returns:URL for the actor.
as_json()[source]

Notification data in a Python dictionary to which later gets supplied to JSONResponse so that it gets JSON serialized the django-way

Returns:Dictionary format of the QuerySet object.
static do_escape(obj)[source]

Method to HTML escape an object or set it to None conditionally. performs force_text() on the argument so that a foreignkey gets serialized? and spit out the __str__ output instead of an Object.

Parameters:obj – Object to escape.
Returns:HTML escaped and JSON-friendly data.
mark_as_read()[source]

Marks notification as read

mark_as_unread()[source]

Marks notification as unread.

obj

See actor property.

Returns:Action Object or Text or None.
obj_url

See actor_url property.

Returns:URL for Action Object.
target

See actor property

Returns:Target object or Text or None
target_url

See actor_url property.

Returns:URL for the target.
class notify.models.NotificationQueryset(model=None, query=None, using=None, hints=None)[source]

Chain-able QuerySets using `.as_manager().

active()[source]

QuerySet filter() for retrieving both read and unread notifications which are not soft-deleted.

Returns:Non soft-deleted notifications.
active_all(user=None)[source]

Method to soft-delete all notifications of a User (if supplied)

Parameters:user – Notification recipient.
Returns:Updates QuerySet as soft-deleted.
delete_all(user=None)[source]

Method to soft-delete all notifications of a User (if supplied)

Parameters:user – Notification recipient.
Returns:Updates QuerySet as soft-deleted.
deleted()[source]

QuerySet filter() for retrieving soft-deleted notifications.

Returns:Soft deleted notification filter()
prefetch()[source]

Marks the current queryset to prefetch all generic relations.

read()[source]

QuerySet filter() for retrieving read notifications.

Returns:Read and active Notifications filter().
read_all(user=None)[source]

Marks all notifications as read for a user (if supplied)

Parameters:user – Notification recipient.
Returns:Updates QuerySet as read.
unread()[source]

QuerySet filter() for retrieving unread notifications.

Returns:Unread and active Notifications filter().
unread_all(user=None)[source]

Marks all notifications as unread for a user (if supplied)

Parameters:user – Notification recipient.
Returns:Updates QuerySet as unread.