<commit_before>from django.forms import widgets

from ideascube.configuration import get_config
from django.utils.html import mark_safe, escape
from django.utils.encoding import force_text
from django.forms.utils import flatatt
from django.utils.translation import get_language

import bleach


_ideascube_to_tinyMCE_language_map = {
    'fr': 'fr_FR'
}


class RichTextEntry(widgets.Widget):
    def __init__(self, *, with_media=False, attrs=None):
        super().__init__(attrs=attrs)
        self.with_media = with_media

        self.authorized_tags = [
            'p', 'a', 'ul', 'ol', 'li',
            'h1', 'h2', 'h3', 'h4', 'h5',
            'strong', 'em',
            'br',
        ]
        self.authorized_attributes = {
            'a': ['href', 'title'],
            'img': ['src', 'width', 'height', 'alt'],
            'iframe': ['src', 'width', 'height', 'allowfullscreen']
        }
        if with_media:
            self.authorized_tags += ['img', 'iframe']

    def get_language(self):
        ideascube_language = get_language()
        return _ideascube_to_tinyMCE_language_map.get(
            ideascube_language, ideascube_language)

    def render(self, name, value, attrs=None):
        if value is None:
            value = ''

        # The widget displayed to the user
        div_attrs = {'id': name,
                     'class': 'tinymce-editor',
                     'data-tinymce-use-media': self.with_media,
                     'data-tinymce-language-code': self.get_language()
                    }
        div_html = '<div{}>{}</div>'.format(
            flatatt(div_attrs),
            force_text(value)
        )

        # The input used by django
        input_attrs = self.build_attrs(attrs, name=name, value=escape(value),
                                       type='hidden')
        input_html = '<input{} />'.format(
            flatatt(input_attrs)
        )

        html = '\n'.join([div_html, input_html])<commit_msg>django-1.11: Adapt to the build_attrs change<commit_after>from django.forms import widgets

from ideascube.configuration import get_config
from django.utils.html import mark_safe, escape
from django.utils.encoding import force_text
from django.forms.utils import flatatt
from django.utils.translation import get_language

import bleach


_ideascube_to_tinyMCE_language_map = {
    'fr': 'fr_FR'
}


class RichTextEntry(widgets.Widget):
    def __init__(self, *, with_media=False, attrs=None):
        super().__init__(attrs=attrs)
        self.with_media = with_media

        self.authorized_tags = [
            'p', 'a', 'ul', 'ol', 'li',
            'h1', 'h2', 'h3', 'h4', 'h5',
            'strong', 'em',
            'br',
        ]
        self.authorized_attributes = {
            'a': ['href', 'title'],
            'img': ['src', 'width', 'height', 'alt'],
            'iframe': ['src', 'width', 'height', 'allowfullscreen']
        }
        if with_media:
            self.authorized_tags += ['img', 'iframe']

    def get_language(self):
        ideascube_language = get_language()
        return _ideascube_to_tinyMCE_language_map.get(
            ideascube_language, ideascube_language)

    def render(self, name, value, attrs=None):
        if value is None:
            value = ''

        if attrs is None:
            attrs = {}

        # The widget displayed to the user
        div_attrs = {'id': name,
                     'class': 'tinymce-editor',
                     'data-tinymce-use-media': self.with_media,
                     'data-tinymce-language-code': self.get_language()
                    }
        div_html = '<div{}>{}</div>'.format(
            flatatt(div_attrs),
            force_text(value)
        )

        # The input used by django
        attrs.update({'name': name, 'value': escape(value), 'type': 'hidden'})

        input_attrs = self.build_attrs(attrs)
        input_html = '<input{} />'.format(
            flatatt(input_attrs)
        )

        html = '\n'.join([div_html, input_html])
{'fraction_non_alphanumeric': 0.13162478228415028, 'fraction_numerical': 0.0032346354814630504, 'mean_word_length': 2.111455108359133, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3786023', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1191, 'n_words': 264}