Views

notify.views.delete(request, *args, **kwargs)[source]

Deletes notification of supplied notification ID.

Depending on project settings, if NOTIFICATIONS_SOFT_DELETE is set to False, the notifications will be deleted from DB. If not, a soft delete will be performed.

By default, notifications are deleted softly.

Parameters:request – HTTP request context.
Returns:Response to delete action on supplied notification ID.
notify.views.mark(request, *args, **kwargs)[source]

Handles marking of individual notifications as read or unread. Takes notification id and mark action as POST data.

Parameters:request – HTTP request context.
Returns:Response to mark action of supplied notification ID.
notify.views.mark_all(request, *args, **kwargs)[source]

Marks notifications as either read or unread depending of POST parameters. Takes action as POST data, it can either be read or unread.

Parameters:request – HTTP Request context.
Returns:Response to mark_all action.
notify.views.notification_redirect(request, ctx)[source]

Helper to handle HTTP response after an action is performed on notification

Parameters:
  • request – HTTP request context of the notification
  • ctx – context to be returned when a AJAX call is made.
Returns:

Either JSON for AJAX or redirects to the calculated next page.

notify.views.notification_update(request, *args, **kwargs)[source]

Handles live updating of notifications, follows ajax-polling approach.

Read more: http://stackoverflow.com/a/12855533/4726598

Required URL parameters: flag.

Explanation:

  • The flag parameter carries the last notification ID received by the user’s browser.

  • This flag is most likely to be generated by using a simple JS/JQuery DOM. Just grab the first element of the notification list.

    • The element will have a data-id attribute set to the corresponding notification.
    • We’ll use it’s value as the flag parameter.
  • The view treats the last notification flag as a model `filter() and fetches all notifications greater than the flag for the user.

  • Then the a JSON data is prepared with all necessary details such as, verb, actor, target and their URL etc. The foreignkey are serialized as their default __str__ value.

    • Everything will be HTML escaped by django’s escape().
  • Since these notification sent will only serve temporarily on the notification box and will be generated fresh using a whole template, to avoid client-side notification generation using the JSON data, the JSON data will also contain a rendered HTML string so that you can easily do a JQuery $yourNotificationBox.prepend() on the rendered html string of the notification.

  • The template used is expected to be different than the template used in full page notification as the css and some other elements are highly likely to be different than the full page notification list.

  • The template used will be the notification type of the notification suffixed _box.html. So, if your notification type is comment_reply, the template will be comment_reply_box.html.

    • This template will be stored in notifications/includes/ of your template directory.
    • That makes: notifications/includes/comment_reply_box.html
  • The rest is self-explanatory.

Parameters:request – HTTP request context.
Returns:Notification updates (if any) in JSON format.
notify.views.notifications(request, *args, **kwargs)[source]

Returns a rendered page of all notifications for the logged-in user. Uses notification.nf_type as the template for individual notification. Each notification type is expected to have a render template at notifications/includes/NOTIFICATION_TYPE.html.

Parameters:request – HTTP request context.
Returns:Rendered notification list page.
notify.views.read_and_redirect(request, *args, **kwargs)[source]

Marks the supplied notification as read and then redirects to the supplied URL from the next URL parameter.

IMPORTANT: This is CSRF - unsafe method. Only use it if its okay for you to mark notifications as read without a robust check.

Parameters:
  • request – HTTP request context.
  • notification_id – ID of the notification to be marked a read.
Returns:

Redirect response to a valid target url.