<commit_before># -*- coding: utf-8 -*-

from django.contrib.auth.models import Permission
from django.db.models import ObjectDoesNotExist
from django.db.models.signals import post_save, post_delete

from pybb.subscription import notify_topic_subscribers
from pybb import defaults
from pybb.models import Profile

from pybb import util
User = util.get_user_model()
username_field = util.get_username_field()


def post_saved(instance, **kwargs):
    notify_topic_subscribers(instance)

    if util.get_pybb_profile(instance.user).autosubscribe:
        instance.topic.subscribers.add(instance.user)

    if kwargs['created']:
        profile = util.get_pybb_profile(instance.user)
        profile.post_count = instance.user.posts.count()
        profile.save()


def post_deleted(instance, **kwargs):
    profile = util.get_pybb_profile(instance.user)
    profile.post_count = instance.user.posts.count()
    profile.save()


def user_saved(instance, created, **kwargs):
    if not created:
        return
    try:
        add_post_permission = Permission.objects.get_by_natural_key('add_post', 'pybb', 'post')
        add_topic_permission = Permission.objects.get_by_natural_key('add_topic', 'pybb', 'topic')
    except ObjectDoesNotExist:
        return
    instance.user_permissions.add(add_post_permission, add_topic_permission)
    instance.save()
    if util.get_pybb_profile_model() == Profile:
        Profile(user=instance).save()


def setup_signals():
    from models import Post
    post_save.connect(post_saved, sender=Post)
    post_delete.connect(post_deleted, sender=Post)
    if defaults.PYBB_AUTO_USER_PERMISSIONS:
        post_save.connect(user_saved, sender=User)<commit_msg>move import to top of the module<commit_after># -*- coding: utf-8 -*-

from django.contrib.auth.models import Permission
from django.db.models import ObjectDoesNotExist
from django.db.models.signals import post_save, post_delete

from pybb.subscription import notify_topic_subscribers
from pybb import defaults
from pybb.models import Profile, Post

from pybb import util
User = util.get_user_model()
username_field = util.get_username_field()


def post_saved(instance, **kwargs):
    notify_topic_subscribers(instance)

    if util.get_pybb_profile(instance.user).autosubscribe:
        instance.topic.subscribers.add(instance.user)

    if kwargs['created']:
        profile = util.get_pybb_profile(instance.user)
        profile.post_count = instance.user.posts.count()
        profile.save()


def post_deleted(instance, **kwargs):
    profile = util.get_pybb_profile(instance.user)
    profile.post_count = instance.user.posts.count()
    profile.save()


def user_saved(instance, created, **kwargs):
    if not created:
        return
    try:
        add_post_permission = Permission.objects.get_by_natural_key('add_post', 'pybb', 'post')
        add_topic_permission = Permission.objects.get_by_natural_key('add_topic', 'pybb', 'topic')
    except ObjectDoesNotExist:
        return
    instance.user_permissions.add(add_post_permission, add_topic_permission)
    instance.save()
    if util.get_pybb_profile_model() == Profile:
        Profile(user=instance).save()


def setup_signals():
    post_save.connect(post_saved, sender=Post)
    post_delete.connect(post_deleted, sender=Post)
    if defaults.PYBB_AUTO_USER_PERMISSIONS:
        post_save.connect(user_saved, sender=User)
{'fraction_non_alphanumeric': 0.09955686853766617, 'fraction_numerical': 0.0005908419497784342, 'mean_word_length': 4.340694006309148, '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': '6091205', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1037, 'n_words': 200}