<commit_before>from django.db.models import ForeignKey, SlugField

from django import forms
from django.utils.translation import ugettext_lazy as _

from ella.ellaadmin import widgets, fields


class EllaAdminOptionsMixin(object):
    def formfield_for_dbfield(self, db_field, **kwargs):
        if isinstance(db_field, SlugField):
            kwargs.update({
                'required': not db_field.blank,
                'max_length': db_field.max_length,
                'label': db_field.verbose_name,
                'error_message': _('Enter a valid slug.'),
})
            return forms.RegexField('^[0-9a-z-]+$', **kwargs)

        for css_class, rich_text_fields in getattr(self, 'rich_text_fields', {}).iteritems():
            if db_field.name in rich_text_fields:
                kwargs.update({
                    'required': not db_field.blank,
                    'label': db_field.verbose_name,
})
                rich_text_field = fields.RichTextAreaField(**kwargs)
                if css_class:
                    rich_text_field.widget.attrs['class'] += ' %s' % css_class
                return rich_text_field

        if db_field.name == 'category':
            return fields.CategorySuggestField(db_field, **kwargs)

        if db_field.name in self.raw_id_fields and isinstance(db_field, ForeignKey):
            kwargs['widget'] = widgets.ForeignKeyRawIdWidget(db_field.rel)
            return db_field.formfield(**kwargs)

        if db_field.name in ('target_ct', 'source_ct', 'content_type',):
            kwargs['widget'] = widgets.ContentTypeWidget
        elif db_field.name in ('target_id', 'source_id', 'object_id',):
            kwargs['widget'] = widgets.ForeignKeyGenericRawIdWidget<commit_msg>suggester is not working - temporarily disabled..<commit_after>from django.db.models import ForeignKey, SlugField

from django import forms
from django.utils.translation import ugettext_lazy as _

from ella.ellaadmin import widgets, fields


class EllaAdminOptionsMixin(object):
    def formfield_for_dbfield(self, db_field, **kwargs):
        if isinstance(db_field, SlugField):
            kwargs.update({
                'required': not db_field.blank,
                'max_length': db_field.max_length,
                'label': db_field.verbose_name,
                'error_message': _('Enter a valid slug.'),
})
            return forms.RegexField('^[0-9a-z-]+$', **kwargs)

        for css_class, rich_text_fields in getattr(self, 'rich_text_fields', {}).iteritems():
            if db_field.name in rich_text_fields:
                kwargs.update({
                    'required': not db_field.blank,
                    'label': db_field.verbose_name,
})
                rich_text_field = fields.RichTextAreaField(**kwargs)
                if css_class:
                    rich_text_field.widget.attrs['class'] += ' %s' % css_class
                return rich_text_field

#        if db_field.name == 'category':
#            return fields.CategorySuggestField(db_field, **kwargs)

        if db_field.name in self.raw_id_fields and isinstance(db_field, ForeignKey):
            kwargs['widget'] = widgets.ForeignKeyRawIdWidget(db_field.rel)
            return db_field.formfield(**kwargs)

        if db_field.name in ('target_ct', 'source_ct', 'content_type',):
            kwargs['widget'] = widgets.ContentTypeWidget
        elif db_field.name in ('target_id', 'source_id', 'object_id',):
            kwargs['widget'] = widgets.ForeignKeyGenericRawIdWidget
{'fraction_non_alphanumeric': 0.10885714285714286, 'fraction_numerical': 0.001142857142857143, 'mean_word_length': 2.536363636363636, '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': '5292356', 'n_tokens_mistral': 1027, 'n_tokens_neox': 984, 'n_words': 210}