Exemple #1
0
class UEditorWidget(forms.Textarea):
    def __init__(self,width=600,height=300,plugins=(),toolbars="normal",filePath="",imagePath="",scrawlPath="",imageManagerPath="",css="",options={}, attrs=None,**kwargs):
        self.ueditor_options=MadeUeditorOptions(width,height,plugins,toolbars,filePath,imagePath,scrawlPath,imageManagerPath,css,options)
        super(UEditorWidget, self).__init__(attrs)

    def render(self, name, value, attrs=None):
        if not self.ueditor_options.get("urled"):
            MakeReverseUrl(self.ueditor_options)
        if value is None:
            value = ''
        #取得工具栏设置
        try:
            if type(self.ueditor_options['toolbars'])==list:
                tbar=json.dumps(self.ueditor_options['toolbars'])
            else:
                # if getattr(USettings,"TOOLBARS_SETTINGS",{}).has_key(str(self.ueditor_options['toolbars'])):
                if str(self.ueditor_options['toolbars']) in getattr(USettings,"TOOLBARS_SETTINGS",{}):
                    if self.ueditor_options['toolbars'] =="full":
                        tbar=None
                    else:
                        tbar=json.dumps(USettings.TOOLBARS_SETTINGS[str(self.ueditor_options['toolbars'])])
                else:
                    tbar=None
        except:
            pass

        #传入模板的参数
        uOptions=self.ueditor_options.copy()
        uOptions.update({
            "name":name,
            "value":conditional_escape(force_unicode(value)),
            "toolbars":tbar,
            "options":json.dumps(self.ueditor_options['options'])[1:-1]
            #str(self.ueditor_options['options'])[1:-1].replace("True","true").replace("False","false").replace("'",'"')
        })
        context = {
            'UEditor':uOptions,
            'STATIC_URL':settings.STATIC_URL,
            'STATIC_ROOT':settings.STATIC_ROOT,
            'MEDIA_URL':settings.MEDIA_URL,
            'MEDIA_ROOT':settings.MEDIA_ROOT
        }
        return mark_safe(render_to_string('ueditor.html',context))

    class Media:
        css={"all": (
            "django_ueditor/themes/default/css/ueditor.css",
            "django_ueditor/themes/iframe.css",
        )}
        js=("django_ueditor/editor_config.js",
            "django_ueditor/editor_all_min.js")
Exemple #2
0
 def __init__(self,
              width=600,
              height=300,
              plugins=(),
              toolbars="normal",
              filePath="",
              imagePath="",
              scrawlPath="",
              imageManagerPath="",
              css="",
              options={},
              attrs=None,
              **kwargs):
     self.ueditor_options = MadeUeditorOptions(width, height, plugins,
                                               toolbars, filePath,
                                               imagePath, scrawlPath,
                                               imageManagerPath, css,
                                               options)
     super(UEditorWidget, self).__init__(attrs)
Exemple #3
0
class UEditorWidget(forms.Textarea):
    def __init__(self,width=600,height=300,plugins=(),toolbars="normal",filePath="",imagePath="",scrawlPath="",imageManagerPath="",css="",options={}, attrs=None,**kwargs):
        self.ueditor_options=MadeUeditorOptions(width,height,plugins,toolbars,filePath,imagePath,scrawlPath,imageManagerPath,css,options)
        super(UEditorWidget, self).__init__(attrs)


    def render(self, name, value, attrs=None):
        if value is None: value = ''
        #取得工具栏设置
        try:
            if type(self.ueditor_options['toolbars'])==list:
                tbar=simplejson.dumps(self.ueditor_options['toolbars'])
            else:
                if getattr(USettings,"TOOLBARS_SETTINGS",{}).has_key(str(self.ueditor_options['toolbars'])):
                    if self.ueditor_options['toolbars'] =="full":
                        tbar=None
                    else:
                        tbar=simplejson.dumps(USettings.TOOLBARS_SETTINGS[str(self.ueditor_options['toolbars'])])
                else:
                    tbar=None
        except:
            pass

        #传入模板的参数
        uOptions=self.ueditor_options.copy()
        uOptions.update({
            "name":name,
            "value":conditional_escape(force_unicode(value)),
            "toolbars":tbar,
            "options":simplejson.dumps(self.ueditor_options['options'])[1:-1]
                #str(self.ueditor_options['options'])[1:-1].replace("True","true").replace("False","false").replace("'",'"')
        })
        context = {
                'UEditor':uOptions,
                'STATIC_URL':settings.STATIC_URL,
                'STATIC_ROOT':settings.STATIC_ROOT,
                'MEDIA_URL':settings.MEDIA_URL,
                'MEDIA_ROOT':settings.MEDIA_ROOT
        }
        return mark_safe(render_to_string('ueditor.html',context))
    class Media:
        css={"all": ("ueditor/themes/default/ueditor.css" ,
                     "ueditor/themes/default/iframe.css" ,
            )}
        js=("ueditor/editor_config.js",
            "ueditor/editor_all_min.js")
Exemple #4
0
 def __init__(self,
              label,
              width=600,
              height=300,
              plugins=(),
              toolbars="normal",
              filePath="",
              imagePath="",
              scrawlPath="",
              imageManagerPath="",
              css="",
              options={},
              *args,
              **kwargs):
     uOptions = MadeUeditorOptions(width, height, plugins, toolbars,
                                   filePath, imagePath, scrawlPath,
                                   imageManagerPath, css, options)
     kwargs["widget"] = UEditorWidget(**uOptions)
     kwargs["label"] = label
     super(UEditorField, self).__init__(*args, **kwargs)
    def __init__(
        self,
        width=600,
        height=300,
        plugins=(),
        toolbars="normal",
        filePath="",
        imagePath="",
        scrawlPath="",
        imageManagerPath="",
        css="",
        options={},
        attrs=None,
        **kwargs
    ):

        self.ueditor_options = MadeUeditorOptions(
            width, height, plugins, toolbars, filePath, imagePath, scrawlPath, imageManagerPath, css, options
        )
        super(UEditorWidget, self).__init__(attrs)
Exemple #6
0
 def __init__(self,
              verbose_name=None,
              width=600,
              height=300,
              plugins=(),
              toolbars="normal",
              filePath="",
              imagePath="",
              scrawlPath="",
              imageManagerPath="",
              css="",
              options={},
              **kwargs):
     self.ueditor_options = MadeUeditorOptions(width, height, plugins,
                                               toolbars, filePath,
                                               imagePath, scrawlPath,
                                               imageManagerPath, css,
                                               options)
     kwargs["verbose_name"] = verbose_name
     super(UEditorField, self).__init__(**kwargs)