more on external editor for Documents; make Documents available via WebDAV
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1152 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
670577cd60
commit
35de5b434a
8 changed files with 61 additions and 10 deletions
|
@ -229,6 +229,13 @@
|
|||
|
||||
<!-- document -->
|
||||
|
||||
<page
|
||||
for="loops.interfaces.IDocument"
|
||||
name="index.html"
|
||||
permission="zope.View"
|
||||
class=".resource.DocumentView"
|
||||
attribute="show" />
|
||||
|
||||
<addform
|
||||
label="Add Document"
|
||||
name="AddLoopsDocument.html"
|
||||
|
@ -236,7 +243,6 @@
|
|||
fields="title data contentType"
|
||||
content_factory="loops.resource.Document"
|
||||
permission="zope.ManageContent" />
|
||||
|
||||
|
||||
<addMenuItem
|
||||
class="loops.resource.Document"
|
||||
|
|
|
@ -31,10 +31,6 @@
|
|||
metal:define-slot="heading">
|
||||
<span tal:content="view/label"
|
||||
i18n:translate="">Edit something</span>
|
||||
<a href="#"
|
||||
tal:condition="python: hasattr(context, 'data')
|
||||
and getattr(context, 'contentType', '').startswith('text')"
|
||||
tal:attributes="href string:${context/@@absolute_url}/external_edit">X</a>
|
||||
</h3>
|
||||
|
||||
<p tal:define="status view/update"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
</div>
|
||||
<div class="content-1"
|
||||
tal:define="target item/target;
|
||||
onclick string:openEditWindow('${item/url}/@@edit_target.html')"
|
||||
onclick string:openEditWindow('${item/url}/@@configure.html')"
|
||||
tal:condition="target"
|
||||
tal:attributes="class string:content-$level;
|
||||
ondblclick python: item.editable and onclick or ''"
|
||||
|
|
|
@ -16,6 +16,12 @@
|
|||
<a href="#"
|
||||
tal:attributes="href string:${target/url}/@@configure.html"
|
||||
tal:content="target/title">Document xy</a>
|
||||
<a href="#" title="External Editor"
|
||||
tal:condition="python:
|
||||
getattr(target.context, 'contentType','').startswith('text')"
|
||||
tal:attributes="href string:${target/context/@@absolute_url}/external_edit"
|
||||
><img src="edit.gif" alt="External Editor"
|
||||
tal:attributes="src context/++resource++edit.gif" /></a>
|
||||
</tal:target>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -130,6 +130,13 @@ class DocumentView(ResourceView):
|
|||
view = zapi.getMultiAdapter((removeAllProxies(source), self.request))
|
||||
return view.render()
|
||||
|
||||
def show(self):
|
||||
data = self.context.data
|
||||
response = self.request.response
|
||||
response.setHeader('Content-Type', self.context.contentType)
|
||||
response.setHeader('Content-Length', len(data))
|
||||
return data
|
||||
|
||||
|
||||
class MediaAssetView(ResourceView):
|
||||
|
||||
|
|
|
@ -5,7 +5,12 @@
|
|||
|
||||
<div metal:fill-slot="body">
|
||||
|
||||
<h1 tal:content="context/title">Concept Title</h1><br />
|
||||
<h1>
|
||||
<span tal:content="context/title">Concept Title</span>
|
||||
<a href="#"
|
||||
tal:condition="python: context.contentType.startswith('text')"
|
||||
tal:attributes="href string:${context/@@absolute_url}/external_edit">X</a>
|
||||
</h1><br />
|
||||
|
||||
<div tal:define="items view/concepts;
|
||||
action string:remove;
|
||||
|
|
|
@ -148,6 +148,10 @@
|
|||
permission="zope.View"
|
||||
interface=".interfaces.IDocument" />
|
||||
|
||||
<require
|
||||
permission="zope.View"
|
||||
interface="zope.app.size.interfaces.ISized" />
|
||||
|
||||
<require
|
||||
permission="zope.ManageContent"
|
||||
set_schema=".interfaces.IDocument" />
|
||||
|
@ -240,6 +244,7 @@
|
|||
<adapter factory="loops.resource.IndexAttributes" />
|
||||
<adapter factory="loops.resource.IndexableResource" />
|
||||
|
||||
<adapter factory="loops.resource.DocumentReadFileAdapter" />
|
||||
<adapter factory="loops.resource.DocumentWriteFileAdapter" />
|
||||
|
||||
<adapter factory="loops.type.ConceptType" />
|
||||
|
|
32
resource.py
32
resource.py
|
@ -26,7 +26,9 @@ from zope.app import zapi
|
|||
from zope.app.container.btree import BTreeContainer
|
||||
from zope.app.container.contained import Contained
|
||||
from zope.app.file.image import Image as BaseMediaAsset
|
||||
from zope.app.filerepresentation.interfaces import IWriteFile
|
||||
from zope.app.file.interfaces import IFile
|
||||
from zope.app.filerepresentation.interfaces import IReadFile, IWriteFile
|
||||
from zope.app.size.interfaces import ISized
|
||||
from zope.component import adapts
|
||||
from zope.i18nmessageid import MessageFactory
|
||||
from zope.interface import implements
|
||||
|
@ -100,7 +102,7 @@ class Resource(Contained, Persistent):
|
|||
|
||||
class Document(Resource):
|
||||
|
||||
implements(IDocument)
|
||||
implements(IDocument, ISized)
|
||||
|
||||
proxyInterface = IDocumentView
|
||||
|
||||
|
@ -109,6 +111,15 @@ class Document(Resource):
|
|||
def getData(self): return self._data
|
||||
data = property(getData, setData)
|
||||
|
||||
def getSize(self):
|
||||
return len(self.data)
|
||||
|
||||
def sizeForSorting(self):
|
||||
return 'byte', self.getSize()
|
||||
|
||||
def sizeForDisplay(self):
|
||||
return '%i Bytes' % self.getSize()
|
||||
|
||||
|
||||
class MediaAsset(Resource, BaseMediaAsset):
|
||||
|
||||
|
@ -155,7 +166,22 @@ class DocumentWriteFileAdapter(object):
|
|||
self.context = context
|
||||
|
||||
def write(self, data):
|
||||
self.context.data = data.replace('\r', '')
|
||||
self.context.data = unicode(data.replace('\r', ''), 'UTF-8')
|
||||
|
||||
|
||||
class DocumentReadFileAdapter(object):
|
||||
|
||||
implements(IReadFile)
|
||||
adapts(IDocument)
|
||||
|
||||
def __init__(self, context):
|
||||
self.context = context
|
||||
|
||||
def read(self):
|
||||
return self.context.data.encode('UTF-8')
|
||||
|
||||
def size(self):
|
||||
return len(self.context.data)
|
||||
|
||||
|
||||
class IndexAttributes(object):
|
||||
|
|
Loading…
Add table
Reference in a new issue