#NEWLINE# @ shared_task ( ) #NEWLINE# def send_moderation_notifications( ) : #NEWLINE# #INDENT# 'Queue up notifications of new messages to moderate' #NEWLINE# from open_connect.accounts.models import User #NEWLINE# top_current_hour = now ( ) . replace ( minute = 0 , second = 0 , microsecond = 0 ) #NEWLINE# top_hour_yesterday = ( top_current_hour - timedelta ( days = 1 ) ) #NEWLINE# owners_with_messages = User . objects . filter ( owned_groups_set__thread__message__status__in = [ 'pending' , 'flagged' ] , owned_groups_set__thread__message__modified_at__lt = top_current_hour , owned_groups_set__thread__message__modified_at__gte = top_hour_yesterday ) . distinct ( ) . only ( 'moderator_notification_period' ) #NEWLINE# can_moderate_all = User . objects . filter ( ( Q ( user_permissions__codename = 'can_moderate_all_messages' ) | Q ( groups__permissions__codename = 'can_moderate_all_messages' ) ) ) #NEWLINE# users_to_notify = set ( ( list ( owners_with_messages ) + list ( users_to_notify ) ) ) #NEWLINE# for user_to_notify in users_to_notify : #NEWLINE# #INDENT# time_period = user_to_notify . moderator_notification_period #NEWLINE# if ( ( time_period != 0 ) and ( ( top_current_hour . hour % time_period ) == 0 ) ) : #NEWLINE# #INDENT# send_moderation_notification . delay ( user_to_notify . pk , top_current_hour . isoformat ( ) )