Merge pull request #136 from yakky/feature/cleanup
Minor code cleanups. Restoring Py3
This commit is contained in:
commit
b415e447d0
|
@ -6,11 +6,11 @@ from cms import __version__ as cms_version
|
|||
from cms.plugin_base import CMSPluginBase
|
||||
from cms.plugin_pool import plugin_pool
|
||||
|
||||
from djangocms_text_ckeditor.settings import TEXT_CKEDITOR_CONFIGURATION
|
||||
from djangocms_text_ckeditor.widgets import TextEditorWidget
|
||||
from djangocms_text_ckeditor.models import Text
|
||||
from djangocms_text_ckeditor.utils import plugin_tags_to_user_html
|
||||
from djangocms_text_ckeditor.forms import TextForm
|
||||
from .settings import TEXT_CKEDITOR_CONFIGURATION
|
||||
from .widgets import TextEditorWidget
|
||||
from .models import Text
|
||||
from .utils import plugin_tags_to_user_html
|
||||
from .forms import TextForm
|
||||
|
||||
|
||||
class TextPlugin(CMSPluginBase):
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from django.db import models
|
||||
from django.contrib.admin import widgets as admin_widgets
|
||||
from djangocms_text_ckeditor.html import clean_html
|
||||
from djangocms_text_ckeditor.widgets import TextEditorWidget
|
||||
from .html import clean_html
|
||||
from .widgets import TextEditorWidget
|
||||
|
||||
try:
|
||||
from south.modelsinspector import add_introspection_rules
|
||||
add_introspection_rules([], ['^djangocms_text_ckeditor\.fields\.HTMLField'])
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
from django import forms
|
||||
from django.forms.models import ModelForm
|
||||
from djangocms_text_ckeditor.models import Text
|
||||
from .models import Text
|
||||
|
||||
|
||||
class TextForm(ModelForm):
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
try:
|
||||
from io import BytesIO as StringIO
|
||||
except:
|
||||
from StringIO import StringIO
|
||||
import uuid
|
||||
import base64
|
||||
from html5lib import sanitizer, serializer, treebuilders, treewalkers
|
||||
import html5lib
|
||||
import re
|
||||
import base64
|
||||
try:
|
||||
from io import BytesIO as StringIO
|
||||
except ImportError:
|
||||
from StringIO import StringIO
|
||||
from PIL import Image
|
||||
import re
|
||||
import uuid
|
||||
|
||||
from .settings import (TEXT_SAVE_IMAGE_FUNCTION, TEXT_ADDITIONAL_TAGS,
|
||||
TEXT_ADDITIONAL_ATTRIBUTES, TEXT_HTML_SANITIZE)
|
||||
from djangocms_text_ckeditor.utils import plugin_to_tag
|
||||
from .utils import plugin_to_tag
|
||||
|
||||
|
||||
def _get_default_parser():
|
||||
|
@ -55,6 +56,7 @@ def clean_html(data, full=True, parser=DEFAULT_PARSER):
|
|||
quote_attr_values=True)
|
||||
return u''.join(s.serialize(stream))
|
||||
|
||||
|
||||
def extract_images(data, plugin):
|
||||
"""
|
||||
extracts base64 encoded images from drag and drop actions in browser and saves
|
||||
|
|
|
@ -6,7 +6,6 @@ try:
|
|||
except ImportError:
|
||||
from django.utils.encoding import force_unicode as force_unicode_or_text
|
||||
|
||||
from django.utils.encoding import force_unicode
|
||||
from django.db import models
|
||||
from django.utils.html import strip_tags
|
||||
from django.utils.text import Truncator
|
||||
|
@ -47,7 +46,8 @@ class AbstractText(CMSPlugin):
|
|||
plugins = CMSPlugin.objects.filter(parent=self)
|
||||
for plugin in plugins:
|
||||
if not plugin.pk in ids:
|
||||
plugin.delete() #delete plugins that are not referenced in the text anymore
|
||||
#delete plugins that are not referenced in the text anymore
|
||||
plugin.delete()
|
||||
|
||||
def post_copy(self, old_instance, ziplist):
|
||||
"""
|
||||
|
@ -123,7 +123,7 @@ class AbstractText(CMSPlugin):
|
|||
order = 1
|
||||
for child in children:
|
||||
replacements['_tag_child_'+str(order)] = plugin_to_tag(child)
|
||||
order+=1
|
||||
order += 1
|
||||
self.body = self.body % replacements
|
||||
self.save()
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
from cms.models.pluginmodel import CMSPlugin
|
||||
from django.conf import settings
|
||||
import os
|
||||
|
||||
|
||||
def create_picture_plugin(filename, file, parent_plugin, **kwargs):
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
from django.conf import settings
|
||||
|
||||
#See http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html for all settings
|
||||
# See http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html
|
||||
# for all settings
|
||||
|
||||
CKEDITOR_SETTINGS = getattr(settings, 'CKEDITOR_SETTINGS', {
|
||||
'language': '{{ language }}',
|
||||
'toolbar': 'CMS',
|
||||
'skin': 'moono',
|
||||
# 'stylesSet': [
|
||||
# {'name': 'Custom Style', 'element': 'h3', 'styles': {'color': 'Blue'}}
|
||||
# ],
|
||||
'toolbarCanCollapse': False,
|
||||
})
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import os
|
||||
import re
|
||||
from django.template.defaultfilters import force_escape
|
||||
import django
|
||||
|
||||
from cms.models import CMSPlugin
|
||||
from distutils.version import LooseVersion
|
||||
from django.utils.functional import LazyObject
|
||||
import django
|
||||
from django.core.files.storage import get_storage_class
|
||||
import os
|
||||
from django.template.defaultfilters import force_escape
|
||||
from django.utils.functional import LazyObject
|
||||
|
||||
OBJ_ADMIN_RE_PATTERN = r'<img [^>]*\bid="plugin_obj_(\d+)"[^>]*/?>'
|
||||
OBJ_ADMIN_RE = re.compile(OBJ_ADMIN_RE_PATTERN)
|
||||
|
||||
|
||||
def plugin_to_tag(obj):
|
||||
return u'<img src="%(icon_src)s" alt="%(icon_alt)s" title="%(icon_alt)s" id="plugin_obj_%(id)d" />' % \
|
||||
dict(id=obj.id,
|
||||
|
@ -18,10 +18,12 @@ def plugin_to_tag(obj):
|
|||
icon_alt=force_escape(obj.get_instance_icon_alt()),
|
||||
)
|
||||
|
||||
|
||||
def plugin_tags_to_id_list(text, regex=OBJ_ADMIN_RE):
|
||||
ids = regex.findall(text)
|
||||
return [int(id) for id in ids if id.isdigit()]
|
||||
|
||||
|
||||
def plugin_tags_to_user_html(text, context, placeholder):
|
||||
"""
|
||||
Convert plugin object 'tags' into the form for public site.
|
||||
|
@ -29,6 +31,7 @@ def plugin_tags_to_user_html(text, context, placeholder):
|
|||
context is the template context to use, placeholder is the placeholder name
|
||||
"""
|
||||
plugin_map = _plugin_dict(text)
|
||||
|
||||
def _render_tag(m):
|
||||
plugin_id = int(m.groups()[0])
|
||||
try:
|
||||
|
@ -41,6 +44,7 @@ def plugin_tags_to_user_html(text, context, placeholder):
|
|||
return obj.render_plugin(context, placeholder)
|
||||
return OBJ_ADMIN_RE.sub(_render_tag, text)
|
||||
|
||||
|
||||
def replace_plugin_tags(text, id_dict):
|
||||
def _replace_tag(m):
|
||||
plugin_id = int(m.groups()[0])
|
||||
|
@ -87,6 +91,7 @@ class ConfiguredStorage(LazyObject):
|
|||
|
||||
configured_storage = ConfiguredStorage()
|
||||
|
||||
|
||||
def static_url(path):
|
||||
'''
|
||||
Helper that prefixes a URL with STATIC_URL and cms
|
||||
|
|
|
@ -6,7 +6,7 @@ from django.template.loader import render_to_string
|
|||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation.trans_real import get_language
|
||||
|
||||
import djangocms_text_ckeditor.settings as text_settings
|
||||
from . import settings as text_settings
|
||||
|
||||
|
||||
class TextEditorWidget(Textarea):
|
||||
|
|
Reference in New Issue