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