Chinaunix首页 | 论坛 | 博客
  • 博客访问: 109848
  • 博文数量: 19
  • 博客积分: 600
  • 博客等级: 上士
  • 技术积分: 230
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-12 04:04
文章分类

全部博文(19)

文章存档

2014年(4)

2009年(2)

2008年(13)

我的朋友

分类: Python/Ruby

2009-04-25 08:05:34

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())

阅读(1917) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~