#NEWLINE# def send_notification( page_revision_id , notification , excluded_user_id ) : #NEWLINE# #INDENT# revision = PageRevision . objects . get ( id = page_revision_id ) #NEWLINE# if ( notification == 'submitted' ) : #NEWLINE# #INDENT# recipients = users_with_page_permission ( revision . page , 'publish' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( notification in [ 'rejected' , 'approved' ] ) : #NEWLINE# #INDENT# recipients = [ revision . user ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# email_recipients = [ recipient for recipient in recipients if ( recipient . email and ( recipient . pk != excluded_user_id ) and getattr ( UserProfile . get_for_user ( recipient ) , ( notification + '_notifications' ) ) ) ] #NEWLINE# if ( not email_recipients ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# template_subject = ( ( 'wagtailadmin/notifications/' + notification ) + '_subject.txt' ) #NEWLINE# template_text = ( ( 'wagtailadmin/notifications/' + notification ) + '.txt' ) #NEWLINE# template_html = ( ( 'wagtailadmin/notifications/' + notification ) + '.html' ) #NEWLINE# context = { #NEWLINE# #INDENT# 'revision' : revision , #NEWLINE# 'settings' : settings , #NEWLINE# #UNINDENT# } #NEWLINE# sent_count = 0 #NEWLINE# for recipient in email_recipients : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# context [ 'user' ] = recipient #NEWLINE# email_subject = render_to_string ( template_subject , context ) . strip ( ) #NEWLINE# email_content = render_to_string ( template_text , context ) . strip ( ) #NEWLINE# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if getattr ( settings , 'WAGTAILADMIN_NOTIFICATION_USE_HTML' , False ) : #NEWLINE# #INDENT# kwargs [ 'html_message' ] = render_to_string ( template_html , context ) #NEWLINE# #UNINDENT# send_mail ( email_subject , email_content , [ recipient . email ] , ** kwargs ) #NEWLINE# sent_count += 1 #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . exception ( "Failed to send notification email '%s' to %s" , email_subject , recipient . email ) #NEWLINE# #UNINDENT# #UNINDENT# return ( sent_count == len ( email_recipients ) )