<commit_before>from django.contrib.contenttypes.generic import GenericRelation
from south.modelsinspector import add_ignored_fields
from django.conf import settings

# Trick rest_framework into serializing these relationships
class SerializableGenericRelation(GenericRelation):
    def __init__(self, *args, **kwargs):
        super(SerializableGenericRelation, self).__init__(*args, **kwargs)
        self.serialize = True

add_ignored_fields(["^wq.db.patterns.base.SerializableGenericRelation"])

# Utility for determining whether models have been swapped
class Swapper(object):
    def swappable_setting(self, app_label, model):
        if app_label == 'auth' and model == 'User':
            return 'AUTH_USER_MODEL'
        return 'WQ_%s_MODEL' % model.upper()

    def is_swapped(self, app_label, model):
        default_model = "%s.%s" % (app_label, model)
        setting = self.swappable_setting(app_label, model)
        value = getattr(settings, setting, default_model)
        if value != default_model:
            return value
        else:
            return False

    def get_swapped_models(self, app_label, models):
        return {
            model: self.is_swapped(app_label, model)
            for model in models
        }

    def load_model(self, app_label, model, orm=None):
        swapped = self.is_swapped(app_label, model)
        if swapped:
            app_label, model = swapped.split('.')
        else:
            if orm is not None:
                return orm['%s.%s' % (app_label, model)]
        
        from django.db.models import get_model
        return get_model(app_label, model)

swapper = Swapper()
<commit_msg>check for valid model class<commit_after>from django.contrib.contenttypes.generic import GenericRelation
from south.modelsinspector import add_ignored_fields
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

# Trick rest_framework into serializing these relationships
class SerializableGenericRelation(GenericRelation):
    def __init__(self, *args, **kwargs):
        super(SerializableGenericRelation, self).__init__(*args, **kwargs)
        self.serialize = True

add_ignored_fields(["^wq.db.patterns.base.SerializableGenericRelation"])

# Utility for determining whether models have been swapped
class Swapper(object):
    def swappable_setting(self, app_label, model):
        if app_label == 'auth' and model == 'User':
            return 'AUTH_USER_MODEL'
        return 'WQ_%s_MODEL' % model.upper()

    def is_swapped(self, app_label, model):
        default_model = "%s.%s" % (app_label, model)
        setting = self.swappable_setting(app_label, model)
        value = getattr(settings, setting, default_model)
        if value != default_model:
            return value
        else:
            return False

    def get_swapped_models(self, app_label, models):
        return {
            model: self.is_swapped(app_label, model)
            for model in models
        }

    def load_model(self, app_label, model, orm=None):
        swapped = self.is_swapped(app_label, model)
        if swapped:
            app_label, model = swapped.split('.')
        else:
            if orm is not None:
                return orm['%s.%s' % (app_label, model)]
        
        from django.db.models import get_model
        cls = get_model(app_label, model)
        if cls is None:
            raise ImproperlyConfigured("Could not find %s.%s!" % (app_label, model))
        return cls

swapper = Swapper()

{'fraction_non_alphanumeric': 0.09165955024195845, 'fraction_numerical': 0.0, 'mean_word_length': 2.891472868217054, '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': '2068252', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1019, 'n_words': 265}