[CMF-checkins] CVS: Products/CMFDefault - Link.py:1.9
Tres Seaver
tseaver@zope.com
Tue, 30 Oct 2001 23:18:49 -0500
Update of /cvs-repository/Products/CMFDefault
In directory cvs.zope.org:/tmp/cvs-serv18201
Modified Files:
Link.py
Log Message:
- Make Links editable via FTP/WebDAV.
=== Products/CMFDefault/Link.py 1.8 => 1.9 ===
import Globals
-from Globals import HTMLFile, HTML
+from Globals import InitializeClass
+from AccessControl import ClassSecurityInfo
from Products.CMFCore.PortalContent import PortalContent
from DublinCore import DefaultDublinCoreImpl
from Products.CMFCore import CMFCorePermissions
from Products.CMFCore.WorkflowCore import WorkflowAction
+from Products.CMFCore.utils import keywordsplitter
+from utils import parseHeadersBody
factory_type_information = ( { 'id' : 'Link'
, 'meta_type' : 'Link'
@@ -158,6 +161,8 @@
(CMFCorePermissions.ModifyPortalContent, ('edit',)),
)
+ security = ClassSecurityInfo()
+
def __init__( self
, id
, title=''
@@ -170,6 +175,7 @@
self.remote_url=remote_url
self.description=description
+ security.declareProtected(CMFCorePermissions.ModifyPortalContent, 'edit')
def edit( self, remote_url ):
"""
Edit the Link
@@ -177,17 +183,73 @@
self.remote_url=remote_url
edit = WorkflowAction(edit)
+ security.declareProtected( CMFCorePermissions.View, 'SearchableText' )
def SearchableText(self):
"""
text for indexing
"""
return "%s %s" % (self.title, self.description)
+ security.declareProtected( CMFCorePermissions.View, 'getRemoteUrl' )
def getRemoteUrl(self):
"""
returns the remote URL of the Link
"""
return self.remote_url
-Globals.default__class_init__(Link)
+ def _writeFromPUT( self, body ):
+
+ headers = {}
+ headers, body = parseHeadersBody(body, headers)
+ self.edit(body)
+
+ headers['Format'] = 'text/url'
+ new_subject = keywordsplitter(headers)
+ headers['Subject'] = new_subject or self.Subject()
+ haveheader = headers.has_key
+ for key, value in self.getMetadataHeaders():
+ if key != 'Format' and not haveheader(key):
+ headers[key] = value
+
+ self.editMetadata(title=headers['Title'],
+ subject=headers['Subject'],
+ description=headers['Description'],
+ contributors=headers['Contributors'],
+ effective_date=headers['Effective_date'],
+ expiration_date=headers['Expiration_date'],
+ format=headers['Format'],
+ language=headers['Language'],
+ rights=headers['Rights'],
+ )
+
+ ## FTP handlers
+ security.declareProtected(CMFCorePermissions.ModifyPortalContent, 'PUT')
+ def PUT(self, REQUEST, RESPONSE):
+ """
+ Handle HTTP (and presumably FTP?) PUT requests.
+ """
+ self.dav__init(REQUEST, RESPONSE)
+ body = REQUEST.get('BODY', '')
+ self._writeFromPUT( body )
+ RESPONSE.setStatus(204)
+ return RESPONSE
+
+ security.declareProtected( CMFCorePermissions.View, 'manage_FTPget' )
+ def manage_FTPget(self):
+ "Get the link as text for FTP download (also used for the WebDAV SRC)"
+ join = string.join
+ lower = string.lower
+ hdrlist = self.getMetadataHeaders()
+ hdrtext = join( map( lambda x: '%s: %s' % ( x[0], x[1] )
+ , hdrlist), '\n' )
+ bodytext = '%s\n\n%s' % ( hdrtext, self.getRemoteUrl() )
+
+ return bodytext
+
+ security.declareProtected( CMFCorePermissions.View, 'get_size' )
+ def get_size( self ):
+ """ Used for FTP and apparently the ZMI now too """
+ return len(self.manage_FTPget())
+
+InitializeClass( Link )