<commit_before>from django.conf import settings
from django.db import models


class UserOwnedModelManager(models.Manager):

    def filter_for_user(self, user, *args, **kwargs):
        return super(UserOwnedModelManager, self).get_queryset().filter(user = user, *args, **kwargs)

    def get_for_user(self, user, *args, **kwargs):
        if 'user' in kwargs:
            kwargs.pop('user')
        return super(UserOwnedModelManager, self).get_queryset().get(user = user, *args, **kwargs)

    def get_or_create_for_user(self, user, **kwargs):
        return super(UserOwnedModelManager, self).get_or_create(user = user, **kwargs)

class UserOwnedModel(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, editable = False)

    objects = UserOwnedModelManager()

    class Meta:
        abstract = True<commit_msg>Rename `UserOwnedModelManager` to just `UserOwnedManager` for consistency with Django naming convention. Replace `_for_user` methods with methods that override the base manager methods - this should help enforce a user context for models, and implement initial set of method overrides in this manner.<commit_after>from django.conf import settings
from django.db import models


class UserOwnedManager(models.Manager):
    """
    Wraps standard Manager query methods and adds a required `user` argument, to enforce all calls
    made through this manager to be made within a user context.
    """

    def all(self, user):
        return super(UserOwnedManager, self).filter(user = user)

    def filter(self, user, **kwargs):
        return super(UserOwnedManager, self).filter(user = user, **kwargs)

    def exclude(self, user, **kwargs):
        return self.filter(user).exclude(**kwargs)

    def get(self, user, *args, **kwargs):
        return super(UserOwnedManager, self).get(user = user, *args, **kwargs)

    def create(self, user, **kwargs):
        return super(UserOwnedManager, self).create(user = user, **kwargs)

    def get_or_create(self, user, defaults = None, **kwargs):
        if defaults is None:
            defaults = {}
        defaults['user'] = user
        return super(UserOwnedManager, self).get_or_create(user = user, defaults = defaults, **kwargs)

    def update_or_create(self, user, defaults = None, **kwargs):
        if defaults is None:
            defaults = {}
        defaults['user'] = user
        return super(UserOwnedManager, self).update_or_create(user = user, defaults = defaults, **kwargs)


class UserOwnedModel(models.Model):
    """
    Base class for models that are owned by a user.
    """

    user = models.ForeignKey(settings.AUTH_USER_MODEL, editable = False)

    objects = UserOwnedManager()
    all_objects = models.Manager()

    class Meta:
        abstract = True
{'fraction_non_alphanumeric': 0.10669077757685352, 'fraction_numerical': 0.0, 'mean_word_length': 3.6565656565656566, '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': '2188952', 'n_tokens_mistral': 788, 'n_tokens_neox': 765, 'n_words': 239}