<commit_before># -*- coding: utf-8 -*-
"""
Coop_cms settings : central place for coop_cms settings
the settings should be accessed from here and not directly from django.conf.settings
"""

import os.path

from django.conf import settings as django_settings
from django.conf.urls import patterns
from django.conf.urls.i18n import i18n_patterns
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from importlib import import_module

from coop_cms.logger import logger


COOP_CMS_NAVTREE_CLASS = 'coop_cms.NavTree'
DEPRECATED_COOP_CMS_NAVTREE_CLASS = getattr(django_settings, 'COOP_CMS_NAVTREE_CLASS', 'basic_cms.NavTree')
DEFAULT_MEDIA_ROOT = ''


def load_class(settings_key, default_value):
    """returns the form to be used for creating a new article"""
    full_class_name = getattr(django_settings, settings_key, '') or default_value
    if full_class_name:
        try:
            module_name, class_name = full_class_name.rsplit('.', 1)
        except ValueError:
            raise ImportError("Unable to import {0}: full path is required".format(full_class_name))
        module = import_module(module_name)
        class_object = getattr(module, class_name)
        return class_object
    return None


def get_navigable_content_types():
    """returns the list of content types of navigable (which can be used in navigation) models"""
    ct_choices = []
    try:
        content_apps = django_settings.COOP_CMS_CONTENT_APPS
    except AttributeError:
        content_apps = []
        not_to_be_mapped = ('south', 'django_extensions', 'd2rq')
        for module in django_settings.INSTALLED_APPS:
            if (not module.startswith('django.')) and (module not in not_to_be_mapped):
                content_apps.append(module)
    apps_labels = [app.rsplit('.')[-1] for app in content_apps]
    navigable_content_types = ContentType.objects.filter(app_label__in=apps_labels).order_by('app_label')
    for content_type in navigable_content_types:
        is_navnode = ((content_type.model == 'navnode') and (content_type.app_label == 'coop_cms'))
        if (not is_navnode) and 'get_absolute_url' in dir(content_type.model_class()):
            ct_choices.append((content_type.id, content_type.app_label + u'.' + content_type.model))
    return ct_choices


def get_navtree_class(defaut_class=None):
    """
    returns the custom navtree class
    Warning : It is not recommend to define a custom NavTree. This feature is deprecated
    """
    if hasattr(get_navtree_class, '_cache_class'):
        return getattr(get_navtree_class, '_cache_class')
    else:
        full_class_name = COOP_CMS_NAVTREE_CLASS
        app_label, model_name = full_class_name.split('.')
        model_name = model_name.lower()
        try:
            content_type = ContentType.objects.get(app_label=app_label, model=model_name)
        except ContentType.DoesNotExist:
            return None
        navtree_class = content_type.model_class()
        setattr(get_navtree_class, '_cache_class', navtree_class)
        return navtree_class


def get_article_class():
    """
    returns the custom Article class
    This makes possible to customize the Article model. However, It must inherit from BaseArticle
    """
    if hasattr(get_article_class, '_cache_class'):
        return getattr(get_article_class, '_cache_class')
    else:
        default_value = ""
        if 'coop_cms.apps.basic_cms' in django_settings.INSTALLED_APPS:
            default_value = 'coop_cms.apps.basic_cms.models.Article'<commit_msg>try to fix migrate error<commit_after># -*- coding: utf-8 -*-
"""
Coop_cms settings : central place for coop_cms settings
the settings should be accessed from here and not directly from django.conf.settings
"""

import os.path

from django.conf import settings as django_settings
from django.conf.urls import patterns
from django.conf.urls.i18n import i18n_patterns
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from importlib import import_module

from coop_cms.logger import logger


COOP_CMS_NAVTREE_CLASS = 'coop_cms.NavTree'
DEPRECATED_COOP_CMS_NAVTREE_CLASS = getattr(django_settings, 'COOP_CMS_NAVTREE_CLASS', 'basic_cms.NavTree')
DEFAULT_MEDIA_ROOT = ''


def load_class(settings_key, default_value):
    """returns the form to be used for creating a new article"""
    full_class_name = getattr(django_settings, settings_key, '') or default_value
    if full_class_name:
        try:
            module_name, class_name = full_class_name.rsplit('.', 1)
        except ValueError:
            raise ImportError("Unable to import {0}: full path is required".format(full_class_name))
        module = import_module(module_name)
        class_object = getattr(module, class_name)
        return class_object
    return None


def get_navigable_content_types():
    """returns the list of content types of navigable (which can be used in navigation) models"""
    ct_choices = []
    try:
        content_apps = django_settings.COOP_CMS_CONTENT_APPS
    except AttributeError:
        content_apps = []
        not_to_be_mapped = ('south', 'django_extensions', 'd2rq')
        for module in django_settings.INSTALLED_APPS:
            if (not module.startswith('django.')) and (module not in not_to_be_mapped):
                content_apps.append(module)
    apps_labels = [app.rsplit('.')[-1] for app in content_apps]
    navigable_content_types = ContentType.objects.filter(app_label__in=apps_labels).order_by('app_label')
    for content_type in navigable_content_types:
        is_navnode = ((content_type.model == 'navnode') and (content_type.app_label == 'coop_cms'))
        if (not is_navnode) and 'get_absolute_url' in dir(content_type.model_class()):
            ct_choices.append((content_type.id, content_type.app_label + u'.' + content_type.model))
    return ct_choices


def get_navtree_class(defaut_class=None):
    """
    returns the custom navtree class
    Warning : It is not recommend to define a custom NavTree. This feature is deprecated
    """
    if hasattr(get_navtree_class, '_cache_class'):
        return getattr(get_navtree_class, '_cache_class')
    else:
        full_class_name = COOP_CMS_NAVTREE_CLASS
        app_label, model_name = full_class_name.split('.')
        model_name = model_name.lower()
        try:
            content_type = ContentType.objects.get(app_label=app_label, model=model_name)
        except ContentType.DoesNotExist:
            return None
        except:
            return None
        navtree_class = content_type.model_class()
        setattr(get_navtree_class, '_cache_class', navtree_class)
        return navtree_class


def get_article_class():
    """
    returns the custom Article class
    This makes possible to customize the Article model. However, It must inherit from BaseArticle
    """
    if hasattr(get_article_class, '_cache_class'):
        return getattr(get_article_class, '_cache_class')
    else:
        default_value = ""
        if 'coop_cms.apps.basic_cms' in django_settings.INSTALLED_APPS:
            default_value = 'coop_cms.apps.basic_cms.models.Article'
{'fraction_non_alphanumeric': 0.08589725741333705, 'fraction_numerical': 0.002505916747876932, 'mean_word_length': 3.6588845654993514, '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': '1416532', 'n_tokens_mistral': 2218, 'n_tokens_neox': 2156, 'n_words': 534}