码迷,mamicode.com
首页 > 其他好文 > 详细

xadmin集成ueditor

时间:2014-08-25 22:28:05      阅读:418      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   java   使用   io   for   ar   

from DjangoUeditor.models import UEditorField

content = UEditorField(u"内容", imagePath="uploadimg/",blank=True, null=True)

 

在adminx.py里

style_fields = {‘content‘: ‘ueditor‘}

 

在adminx里plugins里加入ueditor.py

import xadmin
from django.db.models import TextField
from xadmin.views import BaseAdminPlugin, ModelFormAdminView, DetailAdminView
from DjangoUeditor.models import UEditorField
from DjangoUeditor.widgets import UEditorWidget
from django.conf import settings

class XadminUEditorWidget(UEditorWidget):
    def __init__(self,**kwargs):
        self.ueditor_options=kwargs
        self.Media.js = None
        super(XadminUEditorWidget,self).__init__(kwargs)

class UeditorPlugin(BaseAdminPlugin):

    def get_field_style(self, attrs, db_field, style, **kwargs):
        if style == ‘ueditor‘:
            if isinstance(db_field, UEditorField):
                widget = db_field.formfield().widget
                param = {}
                param.update(widget.ueditor_settings)
                param.update(widget.attrs)
                return {‘widget‘: XadminUEditorWidget(**param)}
            if isinstance(db_field, TextField):
                return {‘widget‘: XadminUEditorWidget}
        return attrs

    def block_extrahead(self, context, nodes):
        js = ‘<script type="text/javascript" src="%s"></script>‘ % (settings.STATIC_URL + "media/ueditor/ueditor.config.js")
        js += ‘<script type="text/javascript" src="%s"></script>‘ % (settings.STATIC_URL + "media/ueditor/ueditor.all.min.js")
        nodes.append(js)

xadmin.site.register_plugin(UeditorPlugin, DetailAdminView)
xadmin.site.register_plugin(UeditorPlugin, ModelFormAdminView)

或者直接将目录放进项目bubuko.com,布布扣

再将ueditor.html放入templates中即可。

在使用到的地方<p>{% autoescape off %}{{ information.content }}{% endautoescape %}</p>

 

xadmin集成ueditor

标签:des   style   blog   http   java   使用   io   for   ar   

原文地址:http://www.cnblogs.com/tuifeideyouran/p/3935942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!