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 anonymousactors
,targets
andobject
.- 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 formatteddifferently during HTML rendering. For this, eachnotification gets to carry it own notification type.This notification type will be used to searchthe special template for the notification located atnotifications/includes/NF_TYPE.html
of yourtemplate directory.The main reason to add this field is to save youfrom the pain of writingif...elif...else
blocksin your template file just for handling hownotifications will get rendered.With this, you can just save template for an individualnotification type and call the template-tag to renderall notifications for you without writing a singleif...elif...else block
.You’ll just need to do a{% render_notifications using NOTIFICATION_OBJ %}
and you’ll get your notifications rendered.By default, everynf_type
is set todefault
.
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 fromactor_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.
-
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
propertyReturns: 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()
-
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: List of updated notifications with status codes
-