def generate_notifications(request, annotation, action):
    # Only send notifications when new annotations are created
    if action != 'create':
        return

    # If the annotation doesn't have a parent, or we can't find its parent,
    # then we can't send a notification email.
    parent_id = annotation.parent_id
    if parent_id is None:
        return

    # Now we know we're dealing with a reply
    reply = annotation

    parent = storage.fetch_annotation(request, parent_id)
    if parent is None:
        return

    # If the parent user doesn't exist (anymore), we can't send an email.
    parent_user = accounts.get_user(parent.userid, request)
    if parent_user is None:
        return

    # If the reply user doesn't exist (anymore), we can't send an email, but
    # this would be super weird, so log a warning.
    reply_user = accounts.get_user(reply.userid, request)
    if reply_user is None:
        log.warn('user who just replied no longer exists: %s', reply.userid)
        return

    # Don't send reply notifications to the author of the parent annotation if
    # the author doesn't have permission to read the reply.
    if not auth.has_permission(request, reply, parent.userid, 'read'):
        return

    # FIXME: we should be retrieving the document from the root annotation, not
    # the reply, and dealing with the possibility that we have no document
    # metadata.
    if reply.document is None:
        return

    # Store the parent values as additional data
    data = {
        'parent': parent
    }

    subscriptions = Subscriptions.get_active_subscriptions_for_a_type('reply')
    for subscription in subscriptions:
        data['subscription'] = subscription.__json__(request)

        # Validate annotation
        if check_conditions(reply, data):
            # TODO: we should not be assuming that the reply has a document
            # property, and instead should use the document associated with the
            # thread root
            yield Notification(reply, reply_user, parent, parent_user, reply.document)


# Create a reply template for a uri
Check if the passed annotation and action pair should send a notification.
dataset/ETHPy150Open hypothesis/h/h/notification/reply_template.py/generate_notifications