<commit_before>#
# Copyright (C) 2017 by frePPLe bv
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

"""
The boot app is placed at the top of the list in ``INSTALLED_APPS``
for the purpose of hooking into Django's ``class_prepared`` signal
and defining attribute fields.

This app is very closely inspired on http://mezzanine.jupo.org/
and its handling of injected extra fields.
"""
import copy
import os
from importlib import import_module
from itertools import chain

from django.conf import settings
from django.db import models

from django.core.exceptions import FieldDoesNotExist, ImproperlyConfigured
from django.db import connections
from django.db.models.signals import class_prepared
from django.db.utils import DEFAULT_DB_ALIAS

from freppledb.common.fields import JSONBField


_register = {}
_register_kwargs = {}


def add_extra_model_fields(sender, **kwargs):
    model_path = "%s.%s" % (sender.__module__, sender.__name__)
    for field_name, label, fieldtype, editable, initially_hidden in chain(
        _register.get(model_path, []), _register.get(sender._meta.db_table, [])
    ):

        register_args = (
            _register_kwargs[(model_path, field_name)]
            if (model_path, field_name) in _register_kwargs
            else None
        )<commit_msg>only allow custom attributes on standard models<commit_after>#
# Copyright (C) 2017 by frePPLe bv
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

"""
The boot app is placed at the top of the list in ``INSTALLED_APPS``
for the purpose of hooking into Django's ``class_prepared`` signal
and defining attribute fields.

This app is very closely inspired on http://mezzanine.jupo.org/
and its handling of injected extra fields.
"""
import copy
import os
from importlib import import_module
from itertools import chain

from django.conf import settings
from django.db import models

from django.core.exceptions import FieldDoesNotExist, ImproperlyConfigured
from django.db import connections
from django.db.models.signals import class_prepared
from django.db.utils import DEFAULT_DB_ALIAS

from freppledb.common.fields import JSONBField


_register = {}
_register_kwargs = {}


def add_extra_model_fields(sender, **kwargs):
    model_path = "%s.%s" % (sender.__module__, sender.__name__)
    for field_name, label, fieldtype, editable, initially_hidden in chain(
        _register.get(model_path, []), _register.get(sender._meta.db_table, [])
    ):
        if sender._meta.parents:
            # Proxy classes can't have attributes
            continue

        register_args = (
            _register_kwargs[(model_path, field_name)]
            if (model_path, field_name) in _register_kwargs
            else None
        )
{'fraction_non_alphanumeric': 0.07102851323828921, 'fraction_numerical': 0.0025458248472505093, 'mean_word_length': 3.986040609137056, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '89830', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1053, 'n_words': 454}