<commit_before>from django.conf import settings
from django.contrib.contenttypes import generic
from django.db import models
from m2m_history.fields import ManyToManyHistoryField
from odnoklassniki_api.decorators import atomic, fetch_all, opt_generator
from odnoklassniki_api.utils import get_improperly_configured_field


class UsersModelMixin(models.Model):

    class Meta:
        abstract = True

    if 'odnoklassniki_users' in settings.INSTALLED_APPS:
        from odnoklassniki_users.models import User
        users = ManyToManyHistoryField(User, cache=True)

        @atomic
        # @opt_generator
        def update_users(self, **kwargs):
            from odnoklassniki_users.models import User
            ids = self.__class__.remote.get_members_ids(group=self)
            first = self.users.versions.count() == 0

            self.users = User.remote.fetch(ids=ids)

            self.members_count = len(ids)
            self.save()

            if first:
                self.users.get_query_set_through().update(time_from=None)
                self.users.versions.update(added_count=0)

            return self.users.all()
    else:
        users = get_improperly_configured_field('odnoklassniki_users', True)
        update_users = get_improperly_configured_field('odnoklassniki_users')


class PhotosModelMixin(models.Model):

    class Meta:
        abstract = True

    if 'odnoklassniki_photos' in settings.INSTALLED_APPS:
        from odnoklassniki_photos.models import Album
        albums = generic.GenericRelation(Album, content_type_field='owner_content_type', object_id_field='owner_id')
        albums_count = models.PositiveIntegerField(null=True)

        def fetch_albums(self, **kwargs):
            return Album.remote.fetch(group=self, **kwargs)
    else:
        albums = get_improperly_configured_field('odnoklassniki_photos', True)
        albums_count = get_improperly_configured_field('odnoklassniki_photos', True)
        fetch_albums = get_improperly_configured_field('odnoklassniki_photos')


class DiscussionsModelMixin(models.Model):

    class Meta:
        abstract = True

    if 'odnoklassniki_discussions' in settings.INSTALLED_APPS:
        from odnoklassniki_discussions.models import Discussion
        discussions = generic.GenericRelation(
            Discussion, content_type_field='owner_content_type', object_id_field='owner_id')
        discussions_count = models.PositiveIntegerField(null=True)

        def fetch_discussions(self, **kwargs):
            return Discussion.remote.fetch_group(group=self, **kwargs)
    else:
        discussions = get_improperly_configured_field('odnoklassniki_discussions', True)
        discussions_count = get_improperly_configured_field('odnoklassniki_discussions', True)
        fetch_discussions = get_improperly_configured_field('odnoklassniki_discussions')
<commit_msg>added imports<commit_after>from django.conf import settings
from django.contrib.contenttypes import generic
from django.db import models
from m2m_history.fields import ManyToManyHistoryField
from odnoklassniki_api.decorators import atomic, fetch_all, opt_generator
from odnoklassniki_api.utils import get_improperly_configured_field


class UsersModelMixin(models.Model):

    class Meta:
        abstract = True

    if 'odnoklassniki_users' in settings.INSTALLED_APPS:
        from odnoklassniki_users.models import User
        users = ManyToManyHistoryField(User, cache=True)

        @atomic
        # @opt_generator
        def update_users(self, **kwargs):
            from odnoklassniki_users.models import User
            ids = self.__class__.remote.get_members_ids(group=self)
            first = self.users.versions.count() == 0

            self.users = User.remote.fetch(ids=ids)

            self.members_count = len(ids)
            self.save()

            if first:
                self.users.get_query_set_through().update(time_from=None)
                self.users.versions.update(added_count=0)

            return self.users.all()
    else:
        users = get_improperly_configured_field('odnoklassniki_users', True)
        update_users = get_improperly_configured_field('odnoklassniki_users')


class PhotosModelMixin(models.Model):

    class Meta:
        abstract = True

    if 'odnoklassniki_photos' in settings.INSTALLED_APPS:
        from odnoklassniki_photos.models import Album
        albums = generic.GenericRelation(Album, content_type_field='owner_content_type', object_id_field='owner_id')
        albums_count = models.PositiveIntegerField(null=True)

        def fetch_albums(self, **kwargs):
            from odnoklassniki_photos.models import Album
            return Album.remote.fetch(group=self, **kwargs)
    else:
        albums = get_improperly_configured_field('odnoklassniki_photos', True)
        albums_count = get_improperly_configured_field('odnoklassniki_photos', True)
        fetch_albums = get_improperly_configured_field('odnoklassniki_photos')


class DiscussionsModelMixin(models.Model):

    class Meta:
        abstract = True

    if 'odnoklassniki_discussions' in settings.INSTALLED_APPS:
        from odnoklassniki_discussions.models import Discussion
        discussions = generic.GenericRelation(
            Discussion, content_type_field='owner_content_type', object_id_field='owner_id')
        discussions_count = models.PositiveIntegerField(null=True)

        def fetch_discussions(self, **kwargs):
            from odnoklassniki_discussions.models import Discussion
            return Discussion.remote.fetch_group(group=self, **kwargs)
    else:
        discussions = get_improperly_configured_field('odnoklassniki_discussions', True)
        discussions_count = get_improperly_configured_field('odnoklassniki_discussions', True)
        fetch_discussions = get_improperly_configured_field('odnoklassniki_discussions')

{'fraction_non_alphanumeric': 0.07466757586089329, 'fraction_numerical': 0.0010228435049437436, 'mean_word_length': 3.58359375, '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': '5875594', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1726, 'n_words': 299}