<commit_before>from django import forms
from django.conf import settings
from django.core.urlresolvers import reverse
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
from django.utils.html import conditional_escape
from django.utils.encoding import force_unicode
from django.utils import simplejson

from django.core.exceptions import ImproperlyConfigured
from django.forms.util import flatatt

import ckeditor.utils as u

json_encode = simplejson.JSONEncoder().encode

DEFAULT_CONFIG = {
    'skin': 'django',
    'toolbar': 'Full',
    'height': 291,
    'width': 835,
    'filebrowserWindowWidth': 940,
    'filebrowserWindowHeight': 725,
}


class CKEditorWidget(forms.Textarea):
    """
    Widget providing CKEditor for Rich Text Editing.
    Supports direct image uploads and embed.
    """

    @property
    def media(self):
        media_prefix = getattr(settings, 'CKEDITOR_MEDIA_PREFIX', settings.STATIC_URL)
        if len(media_prefix) and media_prefix[-1] != '/':
            media_prefix += '/'

        media = super(CKEditorWidget, self).media
        media.add_js([media_prefix + 'ckeditor/ckeditor/ckeditor.js?timestamp=C83J'])
        return media
<commit_msg>Support Promise objects in CKEDITOR_CONFIG<commit_after>import json

from django import forms
from django.conf import settings
from django.core.urlresolvers import reverse
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
from django.utils.encoding import force_unicode
from django.utils.functional import Promise
from django.utils.html import conditional_escape
from django.core.exceptions import ImproperlyConfigured

from django.forms.util import flatatt

import ckeditor.utils as u


class LazyEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, Promise):
            return force_unicode(obj)
        return super(LazyEncoder, self).default(obj)

json_encode = LazyEncoder().encode

DEFAULT_CONFIG = {
    'skin': 'django',
    'toolbar': 'Full',
    'height': 291,
    'width': 835,
    'filebrowserWindowWidth': 940,
    'filebrowserWindowHeight': 725,
}


class CKEditorWidget(forms.Textarea):
    """
    Widget providing CKEditor for Rich Text Editing.
    Supports direct image uploads and embed.
    """

    @property
    def media(self):
        media_prefix = getattr(settings, 'CKEDITOR_MEDIA_PREFIX', settings.STATIC_URL)
        if len(media_prefix) and media_prefix[-1] != '/':
            media_prefix += '/'

        media = super(CKEditorWidget, self).media
        media.add_js([media_prefix + 'ckeditor/ckeditor/ckeditor.js?timestamp=C83J'])
        return media

{'fraction_non_alphanumeric': 0.09198813056379822, 'fraction_numerical': 0.01112759643916914, 'mean_word_length': 3.930530164533821, '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': '1026273', 'n_tokens_mistral': 810, 'n_tokens_neox': 771, 'n_words': 205}