文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>在 Django 中配置 FCKEditor(一)

在 Django 中配置 FCKEditor(一)

时间:2009-04-25  来源:carset

1.在项目下创建 util目录.并新建 __init__.py 文件.内容留空即可

2.在util目录下创建 cache.py 内容如下

# -*- coding:utf-8 -*-

class CacheContainer(object):
   pass


3.在util目录下新建cachemiddleware.py 内容如下

from util.cache import CacheContainer as Cache

class CacheMiddleware(object):
    
    def process_request(self, request):
       Cache.user_agent = request.META.get('HTTP_USER_AGENT',"")


4.在util目录下新建editor.py 内容如下

#!/usr/bin/env python
from django.forms.widgets import Widget
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe

import fckeditor

from util.cache import CacheContainer as Cache

class FCKEditor(Widget):
    def __init__(self, attrs=None):
        if attrs is not None:
            self.attrs = attrs.copy()
        else:
            self.attrs = {}

        self.__widget = fckeditor.FCKeditor("FCKeditor1")
        self.__widget.sAgent = Cache.user_agent or ""
        super(FCKEditor, self).__init__(attrs)

        self.setAtters(self.attrs)

    def setAtters(self, attrs):
        if attrs is None:
            return

        if 'basepath' in attrs:
            self.__widget.BasePath = attrs['basepath']

        if 'width' in attrs:
            self.__widget.Width = attrs['width']

        if 'height' in attrs:
            self.__widget.Height = attrs['height']

        if 'toolbar' in attrs:
            self.__widget.ToolbarSet = attrs['toolbar']

    def render(self, name, value, attrs=None):
        if value is None: value = ''
        value = force_unicode(value)

        self.__widget.InstanceName = name
        self.__widget.Value = value
        self.setAtters(attrs)

        final_attrs = self.build_attrs(attrs, name=name)
        return mark_safe(self.__widget.CreateHtml())

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载