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

xadmin 插件开发

时间:2017-11-01 20:34:45      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:4行   源码   官方   编辑器   修改   .config   xadmin   plugins   read   

xadmin 插件开发


互文本编辑器,UEditor 在github上面搜索djangoueditor,经行安装下载
插件官方文档 网址:http://xadmin.readthedocs.io/en/docs-chinese/plugins.html#
安装流程:
1. pip install DjangoUeditor
2.settings.py 中加入DjangoUeditor

3.在adminx.py文件里面,courseAdmin类里面加入
def save_models(self):
obj = self.new_obj
obj.save()
if obj.course_org is not None:
course_org = obj.course_org
course_org.course_nums = Courses.objects.filter(course_org=course_org).count()
course_org.save()
4.在models里面填入
from DjangoUeditor.models import UEdiitorField
修改该类中的字段内容
detail = UEditorField(verbose_name=u‘课程详情‘,width=600, height=300, imagePath="courser/ueditor/", filePath="courser/ueditor/", default=‘‘)



3.url(r‘ueditor/‘,include(‘DjangoUeditor.urls‘))
在经行这一步时,会报错,需要修改源码
修改DjangoUeditor\urls.py文件中的,
第4行  将from django.conf.urls import patterns, url 改为  from django.conf.urls import url, include
第10行 将

urlpatterns = patterns(‘‘,
    url(r‘^controller/$‘,get_ueditor_controller)
)
改为:
urlpatterns = [
url(r‘^controller/$‘,get_ueditor_controller),
]

在需要修改的app里面的models里面的需要添加ueditor的字段修改为以下字段
4.detai = UEditorField()

5.在\extra_apps\xadmin\plugins下,添加一个文件 ueditor.py
在文件里面填写
# coding=utf-8
import xadmin
from django.db.models import TextField
from xadmin.views import BaseAdminPlugin,CreateAdminView,ModelFormAdminView,UpdateAdminView
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)}
return attrs

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

xadmin.site.register_plugin(UeditorPlugin,UpdateAdminView)
xadmin.site.register_plugin(UeditorPlugin,CreateAdminView)
6.在adminx.py 中,在该类下面添加
style_fields = {"detail":"ueditor"}
7.在\extra_apps\xadmin\plugins下的__init__.py文件中,将‘ueditor‘其添加在后面
8.在前端页面里面 {% autoescape off %}    {% endautoescape %}

xadmin 插件开发

标签:4行   源码   官方   编辑器   修改   .config   xadmin   plugins   read   

原文地址:http://www.cnblogs.com/chenyang13677/p/7768009.html

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