<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals
try:
    from django.contrib.sites.shortcuts import get_current_site
except ImportError:
    from django.contrib.sites.models import get_current_site
from django.core.exceptions import ObjectDoesNotExist
from django.forms import widgets
from django.utils import six
from django.utils.encoding import python_2_unicode_compatible
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from cmsplugin_cascade import settings
from cmsplugin_cascade.fields import PartialFormField
from cmsplugin_cascade.widgets import MultipleCascadingSizeWidget


@python_2_unicode_compatible
class ExtraFieldsMixin(object):
    """
    If a Cascade plugin is listed in ``settings.CMSPLUGIN_CASCADE['plugins_with_extra_fields']``,
    then this ``ExtraFieldsMixin`` class is added automatically to its plugin class in order to
    offer extra fields for customizing CSS classes and styles.
    """

    def __str__(self):
        return self.plugin_class.get_identifier(self)

    def get_form(self, request, obj=None, **kwargs):
        from cmsplugin_cascade.models import PluginExtraFields

        glossary_fields = list(kwargs.pop('glossary_fields', self.glossary_fields))
        try:
            site = get_current_site(request)
            extra_fields = PluginExtraFields.objects.get(plugin_type=self.__class__.__name__, site=site)
        except ObjectDoesNotExist:
            pass
        else:
            # add a text input field to let the user name an ID tag for this HTML element
            if extra_fields.allow_id_tag:
                glossary_fields.append(PartialFormField('extra_element_id',
                    widgets.TextInput(),
                    label=_("Named Element ID"),
                ))

            # add a select box to let the user choose one or more CSS classes
            class_names = extra_fields.css_classes.get('class_names', '').replace(' ', '')
            if class_names:
                choices = [(clsname, clsname) for clsname in class_names.split(',')]
                if extra_fields.css_classes.get('multiple'):
                    widget = widgets.SelectMultiple(choices=choices)
                else:
                    widget = widgets.Select(choices=((None, _("Select CSS")),) + tuple(choices))
                glossary_fields.append(PartialFormField('extra_css_classes',
                    widget,
                    label=_("Customized CSS Classes"),
                    help_text=_("Customized CSS classes to be added to this element.")
                ))

            # add input fields to let the user enter styling information
            for style, choices_tuples in settings.CMSPLUGIN_CASCADE['extra_inline_styles'].items():
                inline_styles = extra_fields.inline_styles.get('extra_fields:{0}'.format(style))
                if not inline_styles:
                    continue
                Widget = choices_tuples[1]
                if issubclass(Widget, MultipleCascadingSizeWidget):
                    key = 'extra_inline_styles:{0}'.format(style)
                    allowed_units = extra_fields.inline_styles.get('extra_units:{0}'.format(style)).split(',')
                    widget = Widget(inline_styles, allowed_units=allowed_units, required=False)
                    glossary_fields.append(PartialFormField(key, widget, label=style))
                else:<commit_msg>changed widget class<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals
try:
    from django.contrib.sites.shortcuts import get_current_site
except ImportError:
    from django.contrib.sites.models import get_current_site
from django.core.exceptions import ObjectDoesNotExist
from django.forms import widgets
from django.utils import six
from django.utils.encoding import python_2_unicode_compatible
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from cmsplugin_cascade import settings
from cmsplugin_cascade.fields import PartialFormField
from cmsplugin_cascade.widgets import MultipleCascadingSizeWidget


@python_2_unicode_compatible
class ExtraFieldsMixin(object):
    """
    If a Cascade plugin is listed in ``settings.CMSPLUGIN_CASCADE['plugins_with_extra_fields']``,
    then this ``ExtraFieldsMixin`` class is added automatically to its plugin class in order to
    offer extra fields for customizing CSS classes and styles.
    """

    def __str__(self):
        return self.plugin_class.get_identifier(self)

    def get_form(self, request, obj=None, **kwargs):
        from cmsplugin_cascade.models import PluginExtraFields

        glossary_fields = list(kwargs.pop('glossary_fields', self.glossary_fields))
        try:
            site = get_current_site(request)
            extra_fields = PluginExtraFields.objects.get(plugin_type=self.__class__.__name__, site=site)
        except ObjectDoesNotExist:
            pass
        else:
            # add a text input field to let the user name an ID tag for this HTML element
            if extra_fields.allow_id_tag:
                glossary_fields.append(PartialFormField('extra_element_id',
                    widgets.TextInput(),
                    label=_("Named Element ID"),
                ))

            # add a select box to let the user choose one or more CSS classes
            class_names = extra_fields.css_classes.get('class_names', '').replace(' ', '')
            if class_names:
                choices = [(clsname, clsname) for clsname in class_names.split(',')]
                if extra_fields.css_classes.get('multiple'):
                    widget = widgets.CheckboxSelectMultiple(choices=choices)
                else:
                    widget = widgets.Select(choices=((None, _("Select CSS")),) + tuple(choices))
                glossary_fields.append(PartialFormField('extra_css_classes',
                    widget,
                    label=_("Customized CSS Classes"),
                    help_text=_("Customized CSS classes to be added to this element.")
                ))

            # add input fields to let the user enter styling information
            for style, choices_tuples in settings.CMSPLUGIN_CASCADE['extra_inline_styles'].items():
                inline_styles = extra_fields.inline_styles.get('extra_fields:{0}'.format(style))
                if not inline_styles:
                    continue
                Widget = choices_tuples[1]
                if issubclass(Widget, MultipleCascadingSizeWidget):
                    key = 'extra_inline_styles:{0}'.format(style)
                    allowed_units = extra_fields.inline_styles.get('extra_units:{0}'.format(style)).split(',')
                    widget = Widget(inline_styles, allowed_units=allowed_units, required=False)
                    glossary_fields.append(PartialFormField(key, widget, label=style))
                else:
{'fraction_non_alphanumeric': 0.08089822945156183, 'fraction_numerical': 0.0020152583849143515, 'mean_word_length': 2.643418982695333, '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': '6188509', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1784, 'n_words': 455}