(request)
Called by clients to wait for notifications for the user. Clients will
    block for a period of time until either expiration or notification
    that a new notification is available.
Called by clients to wait for notifications for the user. Clients will
    block for a period of time until either expiration or notification
    that a new notification is available.
Called by clients to wait for notifications for the user . Clients will block for a period of time until either expiration or notification that a new notification is available .
def poll(request):
    """
    Called by clients to wait for notifications for the user. Clients will
    block for a period of time until either expiration or notification
    that a new notification is available.
    """

    is_user_toast_enabled = request.user.get_preference('toast_notifications', 'enabled', True)

    if is_user_toast_enabled and settings.ENABLE_TOASTS:
        if request.method == 'POST' and request.is_ajax():
            newer_than = request.POST.get("newer_than", None)

            if newer_than == "":
                newer_than = None

            data = get_notification_details(request, newer_than)

            # discount double check of enabled toasts, settings could
            # have changed since a long period of blocking.
            if is_user_toast_enabled and settings.ENABLE_TOASTS:
                return HttpResponse(json.dumps(data),
                                    content_type="application/json")
            else:
                return HttpResponse(status=403)
        else:
            error = "Expected AJAX POST"
            return render(request, "error.html", {"error" : error })
    else:
        # toast notifications are not enabled for this user, return an error
        return HttpResponse(status=403)
def poll ( request ) : is_user_toast_enabled = request . user . get_preference ( 'toast_notifications' , 'enabled' , True ) if is_user_toast_enabled and settings . ENABLE_TOASTS : if request . method == 'POST' and request . is_ajax ( ) : newer_than = request . POST . get ( "newer_than" , None ) if newer_than == "" : newer_than = None data = get_notification_details ( request , newer_than ) # discount double check of enabled toasts, settings could # have changed since a long period of blocking. if is_user_toast_enabled and settings . ENABLE_TOASTS : return HttpResponse ( json . dumps ( data ) , content_type = "application/json" ) else : return HttpResponse ( status = 403 ) else : error = "Expected AJAX POST" return render ( request , "error.html" , { "error" : error } ) else : # toast notifications are not enabled for this user, return an error return HttpResponse ( status = 403 )