<commit_before>import re
from django.conf import settings
from django.conf.urls import url
from django.contrib import admin
from django.core.exceptions import ValidationError
from django.forms import widgets
from django.forms.fields import BooleanField, CharField, ChoiceField, MultipleChoiceField
from django.forms.models import ModelForm
from django.http.response import HttpResponse
from django.template.loader import render_to_string
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from entangled.forms import EntangledModelForm
from cms.plugin_pool import plugin_pool
from cmsplugin_cascade import app_settings
from cmsplugin_cascade.fields import SizeField
from cmsplugin_cascade.models import PluginExtraFields, TextEditorConfigFields, IconFont
from cmsplugin_cascade.extra_fields.mixins import ExtraFieldsMixin


class PluginExtraFieldsForm(EntangledModelForm):
    validation_pattern = re.compile(r'^[A-Za-z0-9_-]+$')

    class_names = CharField(
        label=_("CSS class names"),
        required=False,
        widget=widgets.TextInput(attrs={'style': 'width: 50em;'}),
        help_text=_("Freely selectable CSS classnames for this Plugin, separated by commas."),
    )

    multiple = BooleanField(
        label=_("Allow multiple"),
        required=False,
        help_text=_("Allow to select multiple of the above CSS classes."),
    )

    class Meta:
        untangled_fields = ['plugin_type', 'site']
        entangled_fields = {
            'css_classes': ['class_names', 'multiple'],
            'inline_styles': [],
        }

    def clean_class_names(self):
        value = self.cleaned_data['class_names']
        for val in value.split(','):
            val = val.strip()
            if val and not self.validation_pattern.match(val):
                msg = _("CSS class '{}' contains invalid characters.")
                raise ValidationError(msg.format(val))
        return value


class PluginExtraFieldsAdmin(admin.ModelAdmin):
    list_display = ['name', 'module', 'site', 'allowed_classes_styles']
    DISTANCE_UNITS = [
        ('px,em,rem,%', _("px, em, rem and %")),
        ('px,em,%', _("px, em and %")),
        ('px,rem,em', _("px, rem and em")),
        ('px,em', _("px and em")),
        ('px,rem,%', _("px, rem and %")),
        ('px,%', _("px and %")),
        ('px,rem', _("px and rem")),
        ('px', _("px")),
        ('%,rem', _("% and rem")),
        ('%', _("%")),
    ]

    class Media:
        css = {'all': ('cascade/css/admin/partialfields.css',)}

    @cached_property<commit_msg>add auto as unit option when defining extra fields<commit_after>import re
from django.conf import settings
from django.conf.urls import url
from django.contrib import admin
from django.core.exceptions import ValidationError
from django.forms import widgets
from django.forms.fields import BooleanField, CharField, ChoiceField, MultipleChoiceField
from django.forms.models import ModelForm
from django.http.response import HttpResponse
from django.template.loader import render_to_string
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from entangled.forms import EntangledModelForm
from cms.plugin_pool import plugin_pool
from cmsplugin_cascade import app_settings
from cmsplugin_cascade.fields import SizeField
from cmsplugin_cascade.models import PluginExtraFields, TextEditorConfigFields, IconFont
from cmsplugin_cascade.extra_fields.mixins import ExtraFieldsMixin


class PluginExtraFieldsForm(EntangledModelForm):
    validation_pattern = re.compile(r'^[A-Za-z0-9_-]+$')

    class_names = CharField(
        label=_("CSS class names"),
        required=False,
        widget=widgets.TextInput(attrs={'style': 'width: 50em;'}),
        help_text=_("Freely selectable CSS classnames for this Plugin, separated by commas."),
    )

    multiple = BooleanField(
        label=_("Allow multiple"),
        required=False,
        help_text=_("Allow to select multiple of the above CSS classes."),
    )

    class Meta:
        untangled_fields = ['plugin_type', 'site']
        entangled_fields = {
            'css_classes': ['class_names', 'multiple'],
            'inline_styles': [],
        }

    def clean_class_names(self):
        value = self.cleaned_data['class_names']
        for val in value.split(','):
            val = val.strip()
            if val and not self.validation_pattern.match(val):
                msg = _("CSS class '{}' contains invalid characters.")
                raise ValidationError(msg.format(val))
        return value


class PluginExtraFieldsAdmin(admin.ModelAdmin):
    list_display = ['name', 'module', 'site', 'allowed_classes_styles']
    DISTANCE_UNITS = [
        ('px,em,rem,%', _("px, em, rem and %")),
        ('px,em,%', _("px, em and %")),
        ('px,rem,em', _("px, rem and em")),
        ('px,em', _("px and em")),
        ('px,rem,%', _("px, rem and %")),
        ('px,%', _("px and %")),
        ('px,rem', _("px and rem")),
        ('px', _("px")),
        ('%,rem', _("% and rem")),
        ('%', _("%")),
        ('px,em,rem,%,auto', _("px, em, rem, % and auto")),
        ('px,em,%,auto', _("px, em, % and auto")),
        ('px,rem,em,auto', _("px, rem, em and auto")),
        ('px,em,auto', _("px, em and auto")),
        ('px,rem,%,auto', _("px, rem, % and auto")),
        ('px,%,,auto', _("px, % and auto")),
        ('px,rem,auto', _("px, rem and auto")),
        ('px,auto', _("px and auto")),
        ('%,rem,auto', _("%, rem and auto")),
        ('%,auto', _("% and auto")),
    ]

    class Media:
        css = {'all': ('cascade/css/admin/partialfields.css',)}

    @cached_property
{'fraction_non_alphanumeric': 0.1450061220920063, 'fraction_numerical': 0.0013993353157250306, 'mean_word_length': 3.279940119760479, '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': '808584', 'n_tokens_mistral': 1730, 'n_tokens_neox': 1691, 'n_words': 446}