#NEWLINE# def find_and_fire_hook( event_name , instance , user_override = None ) : #NEWLINE# #INDENT# '\n    Look up Hooks that apply\n    ' #NEWLINE# from django.contrib.auth.models import User #NEWLINE# from rest_hooks.models import Hook , HOOK_EVENTS #NEWLINE# if ( not ( event_name in HOOK_EVENTS . keys ( ) ) ) : #NEWLINE# #INDENT# raise Exception ( '"{}" does not exist in `settings.HOOK_EVENTS`.' . format ( event_name ) ) #NEWLINE# #UNINDENT# filters = { #NEWLINE# #INDENT# 'event' : event_name , #NEWLINE# #UNINDENT# } #NEWLINE# if ( user_override is not False ) : #NEWLINE# #INDENT# if user_override : #NEWLINE# #INDENT# filters [ 'user' ] = user_override #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if hasattr ( instance , 'user' ) : #NEWLINE# #INDENT# filters [ 'user' ] = instance . user #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( instance , User ) : #NEWLINE# #INDENT# filters [ 'user' ] = instance #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Exception ( '{} has no `user` property. REST Hooks needs this.' . format ( repr ( instance ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# hooks = Hook . objects . filter ( ** filters ) #NEWLINE# for hook in hooks : #NEWLINE# #INDENT# hook . deliver_hook ( instance )