#NEWLINE# def generate_notifications( request , annotation , action ) : #NEWLINE# #INDENT# '\n    Check if the passed annotation and action pair should send a notification.\n\n    Checks to see if the annotation event represented by the passed annotation\n    and action should trigger a notification. If it should, this function\n    yields the relevant :py:class:`~h.notification.reply.Notification` object.\n\n    :param request: the current request object\n    :type request: pyramid.request.Request\n    :param annotation: the reply annotation\n    :type annotation: h.api.models.elastic.Annotation or h.models.Annotation\n    :param action: the event action\n    :type action: str\n\n    :returns: :py:class:`~h.notification.reply.Notification` instances\n    ' #NEWLINE# if ( action != 'create' ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# parent_id = annotation . parent_id #NEWLINE# if ( parent_id is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# reply = annotation #NEWLINE# parent = storage . fetch_annotation ( request , parent_id ) #NEWLINE# if ( parent is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# parent_user = accounts . get_user ( parent . userid , request ) #NEWLINE# if ( parent_user is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# reply_user = accounts . get_user ( reply . userid , request ) #NEWLINE# if ( reply_user is None ) : #NEWLINE# #INDENT# log . warn ( 'user who just replied no longer exists: %s' , reply . userid ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( not auth . has_permission ( request , reply , parent . userid , 'read' ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( reply . document is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# data = { #NEWLINE# #INDENT# 'parent' : parent , #NEWLINE# #UNINDENT# } #NEWLINE# subscriptions = Subscriptions . get_active_subscriptions_for_a_type ( 'reply' ) #NEWLINE# for subscription in subscriptions : #NEWLINE# #INDENT# data [ 'subscription' ] = subscription . __json__ ( request ) #NEWLINE# if check_conditions ( reply , data ) : #NEWLINE# #INDENT# ( yield Notification ( reply , reply_user , parent , parent_user , reply . document ) )