<s> """<STR_LIT>""" <EOL> from open_connect . connectmessages . models import Message , MESSAGE_STATUSES <EOL> from open_connect . moderation . models import MessageModerationAction <EOL> from open_connect . connectmessages . tasks import send_message <EOL> POSSIBLE_ACTIONS = [ statuspair [ <NUM_LIT:0> ] for statuspair in MESSAGE_STATUSES ] <EOL> def moderate_messages ( actions , moderator ) : <EOL> """<STR_LIT>""" <EOL> total_changes = <NUM_LIT:0> <EOL> for action , message_ids in actions . iteritems ( ) : <EOL> messages = Message . objects . filter ( pk__in = message_ids ) <EOL> if not moderator . has_perm ( '<STR_LIT>' ) : <EOL> messages = messages . filter ( <EOL> thread__group__in = moderator . groups_moderating ) <EOL> total_changes += messages . update ( status = action ) <EOL> for message in messages : <EOL> moderation_action = MessageModerationAction . objects . create ( <EOL> message_id = message . pk , <EOL> moderator = moderator , <EOL> newstatus = action <EOL> ) <EOL> message . flags . filter ( <EOL> moderation_action__isnull = True <EOL> ) . update ( moderation_action = moderation_action ) <EOL> thread = message . thread <EOL> thread . total_messages = thread . message_set . filter ( <EOL> status__in = [ '<STR_LIT>' , '<STR_LIT>' ] ) . count ( ) <EOL> thread . save ( ) <EOL> if action == '<STR_LIT>' : <EOL> send_message . delay ( message . pk ) <EOL> return total_changes </s>
