xedit External Editor: initial setup
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1149 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
10c6434de9
commit
8a285b715d
7 changed files with 155 additions and 0 deletions
10
xedit/README.txt
Normal file
10
xedit/README.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
External Editor
|
||||
===============
|
||||
|
||||
($Id$)
|
||||
|
||||
>>> from zope.app.testing import ztapi
|
||||
>>> from zope.app import zapi
|
||||
|
||||
>>> from cybertools.xedit import interfaces
|
||||
>>> from cybertools.xedit.browser import ExternalEditorView
|
4
xedit/__init__.py
Normal file
4
xedit/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
"""
|
||||
$Id$
|
||||
"""
|
||||
|
80
xedit/browser.py
Normal file
80
xedit/browser.py
Normal file
|
@ -0,0 +1,80 @@
|
|||
#
|
||||
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
(View) class(es) for the external editor functionality.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope.app import zapi
|
||||
from zope.event import notify
|
||||
from zope.app.event.objectevent import ObjectModifiedEvent
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.security.proxy import removeSecurityProxy
|
||||
|
||||
|
||||
class ExternalEditorView(object):
|
||||
|
||||
# TODO: don't access context.data directly but via an IReadFile adapter
|
||||
|
||||
def load(self):
|
||||
context = removeSecurityProxy(self.context)
|
||||
data = context.data
|
||||
r = []
|
||||
r.append('url:' + zapi.absoluteURL(context, self.request))
|
||||
r.append('meta_type:' + '.'.join((context.__module__, context.__class__.__name__)))
|
||||
auth = self.request.get('_auth')
|
||||
if auth:
|
||||
print 'ExternalEditorView: auth = ', auth
|
||||
if auth.endswith('\n'):
|
||||
auth = auth[:-1]
|
||||
r.append('auth:' + auth)
|
||||
cookie = self.request.get('HTTP_COOKIE','')
|
||||
if cookie:
|
||||
r.append('cookie:' + cookie)
|
||||
r.append('')
|
||||
r.append(data)
|
||||
result = '\n'.join(r)
|
||||
self.setHeaders(len(result))
|
||||
return fromUnicode(result)
|
||||
|
||||
def save(self):
|
||||
data = self.request.get('editor.data')
|
||||
if data:
|
||||
self.context.data = data
|
||||
notify(ObjectModifiedEvent)
|
||||
|
||||
def lock(self):
|
||||
pass
|
||||
|
||||
def unlock(self):
|
||||
pass
|
||||
|
||||
def setHeaders(self, size):
|
||||
response = self.request.response
|
||||
response.setHeader('Content-Type', 'application/x-zope-xedit')
|
||||
response.setHeader('Content-Length', size)
|
||||
|
||||
|
||||
def fromUnicode(text):
|
||||
if not text:
|
||||
return ''
|
||||
if isinstance(text, unicode):
|
||||
return text.encode('UTF-8')
|
||||
return text
|
19
xedit/configure.zcml
Normal file
19
xedit/configure.zcml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!-- $Id$ -->
|
||||
|
||||
<configure
|
||||
xmlns="http://namespaces.zope.org/browser"
|
||||
xmlns:zope="http://namespaces.zope.org/zope"
|
||||
i18n_domain="zope">
|
||||
|
||||
<pages for="loops.interfaces.IResource"
|
||||
class=".browser.ExternalEditorView"
|
||||
permission="zope.ManageContent">
|
||||
|
||||
<page name="external_edit" attribute="load" />
|
||||
<page name="save" attribute="save" />
|
||||
<page name="lock" attribute="lock" />
|
||||
<page name="unlock" attribute="unlock" />
|
||||
|
||||
</pages>
|
||||
|
||||
</configure>
|
1
xedit/cybertools.xedit-configure.zcml
Normal file
1
xedit/cybertools.xedit-configure.zcml
Normal file
|
@ -0,0 +1 @@
|
|||
<include package="cybertools.xedit" />
|
27
xedit/interfaces.py
Normal file
27
xedit/interfaces.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
interface definitions for the external editor.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope.interface import Interface, Attribute
|
||||
|
||||
|
14
xedit/tests.py
Executable file
14
xedit/tests.py
Executable file
|
@ -0,0 +1,14 @@
|
|||
# $Id$
|
||||
|
||||
import unittest, doctest
|
||||
from zope.testing.doctestunit import DocFileSuite
|
||||
|
||||
|
||||
def test_suite():
|
||||
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
||||
return unittest.TestSuite((
|
||||
DocFileSuite('README.txt', optionflags=flags),
|
||||
))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(defaultTest='test_suite')
|
Loading…
Add table
Reference in a new issue