<commit_before>import logging
from django.db.utils import DatabaseError
from django.db.models.signals import post_save
from django.dispatch import receiver
from request.models import Queue
from dm.api import senddm
from django.utils.translation import gettext as _
from moderation.models import Category
from moderation.models import Queue as ModerationQueue

from community.helpers import activate_language
from request.twitter_request import message_requestor

logger = logging.getLogger(__name__) 

@receiver(post_save, sender=Queue)
def dm_admin(sender, instance, created, **kwargs):
    if (
        created
        and (instance.state == Queue.PENDING)
        and (instance.id == instance.identity)
    ):
        try:
            screen_name = instance.socialuser.screen_name_tag()
        except:
            screen_name = None
        activate_language(instance.community)
        community_name = instance.community.name
        if screen_name:
            text = _("Please handle @{screen_name} follow request for {community_name} community.").format(
                screen_name=screen_name,
                community_name=community_name
            )
        else:
            text = _("You have a new follow request.")
        
        try:
            dev_cat = Category.objects.get(name='dev')
            logger.debug(dev_cat)
        except Category.DoesNotExist:
            return
        try:
            screen_name = instance.community.account.username
        except:
            return
        for dev in dev_cat.socialuser_set.all(): 
            dm = senddm(
                text=text,
                user_id=dev.user_id,
                screen_name=screen_name
            )
            logger.debug(dm)
    
@receiver(post_save, sender=Queue)
def message_requestor_slot(sender, instance, created, **kwargs):
    if (
        created
        and (instance.state == Queue.PENDING)
        and (instance.id == instance.identity)
    ):
        message_requestor(instance)
    
@receiver(post_save, sender=Queue)
def create_moderation_queue(sender, instance, created, **kwargs):
    if (
        created
        and (instance.state == Queue.PENDING)
        and (instance.id == instance.identity)
    ):
        try:
            ModerationQueue.objects.create(
                user_id= instance.uid,
                status_id=None,
                community=instance.community,
                type=ModerationQueue.FOLLOWER,
            )
        except DatabaseError:
            return



                <commit_msg>follow protected user who sends a friend request<commit_after>import logging
from django.db.utils import DatabaseError
from django.db.models.signals import post_save
from django.dispatch import receiver
from request.models import Queue
from dm.api import senddm
from django.utils.translation import gettext as _
from moderation.models import Category
from moderation.models import Queue as ModerationQueue
from moderation.twitter.user import TwitterUser
from community.helpers import activate_language
from request.twitter_request import message_requestor

logger = logging.getLogger(__name__) 

@receiver(post_save, sender=Queue)
def dm_admin(sender, instance, created, **kwargs):
    if (
        created
        and (instance.state == Queue.PENDING)
        and (instance.id == instance.identity)
    ):
        try:
            screen_name = instance.socialuser.screen_name_tag()
        except:
            screen_name = None
        activate_language(instance.community)
        community_name = instance.community.name
        if screen_name:
            text = _("Please handle @{screen_name} follow request for {community_name} community.").format(
                screen_name=screen_name,
                community_name=community_name
            )
        else:
            text = _("You have a new follow request.")
        
        try:
            dev_cat = Category.objects.get(name='dev')
            logger.debug(dev_cat)
        except Category.DoesNotExist:
            return
        try:
            screen_name = instance.community.account.username
        except:
            return
        for dev in dev_cat.socialuser_set.all(): 
            dm = senddm(
                text=text,
                user_id=dev.user_id,
                screen_name=screen_name
            )
            logger.debug(dm)
    
@receiver(post_save, sender=Queue)
def message_requestor_slot(sender, instance, created, **kwargs):
    if (
        created
        and (instance.state == Queue.PENDING)
        and (instance.id == instance.identity)
    ):
        message_requestor(instance)
    
@receiver(post_save, sender=Queue)
def create_moderation_queue(sender, instance, created, **kwargs):
    if (
        created
        and (instance.state == Queue.PENDING)
        and (instance.id == instance.identity)
    ):
        try:
            ModerationQueue.objects.create(
                user_id= instance.uid,
                status_id=None,
                community=instance.community,
                type=ModerationQueue.FOLLOWER,
            )
        except DatabaseError:
            return
        
@receiver(post_save, sender=Queue)
def follower_protected_requestor(sender, instance, created, **kwargs):
    if (
        created
        and (instance.state == Queue.PENDING)
        and (instance.id == instance.identity)
    ):
        twitter_user = TwitterUser(socialuser=instance.socialuser)
        if twitter_user.is_protected():
            twitter_user.friend(instance.community)



                
{'fraction_non_alphanumeric': 0.07949040014354926, 'fraction_numerical': 0.0, 'mean_word_length': 2.183323814962878, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2094830', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1442, 'n_words': 341}