Commit b9569e9e authored by Jérome Perrin's avatar Jérome Perrin

WebDAV interface:

 * use locks from portal_classes itself, because locks from temp objects
   cannot be reused (only visible on zope 2.12)
 * reimport files after edition, in an after commit hook, if after commit
   hooks are available (ie. on zope 2.12 only)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34333 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d0141cb0
No related merge requests found
...@@ -35,6 +35,7 @@ from pprint import pformat ...@@ -35,6 +35,7 @@ from pprint import pformat
from Products.CMFCore.utils import UniqueObject from Products.CMFCore.utils import UniqueObject
import OFS import OFS
import transaction
from zExceptions import BadRequest from zExceptions import BadRequest
from zExceptions import Unauthorized from zExceptions import Unauthorized
from Acquisition import Implicit from Acquisition import Implicit
...@@ -66,7 +67,7 @@ from DateTime import DateTime ...@@ -66,7 +67,7 @@ from DateTime import DateTime
import Products import Products
from zLOG import LOG from zLOG import LOG, WARNING
""" """
ClassTool allows to create classes from the ZMI using code templates. ClassTool allows to create classes from the ZMI using code templates.
...@@ -179,8 +180,16 @@ if allowClassTool(): ...@@ -179,8 +180,16 @@ if allowClassTool():
self.size = len(self.data) self.size = len(self.data)
def update_data(self, data, content_type=None, size=None): def update_data(self, data, content_type=None, size=None):
# in OFS.Image.File, all writes are done through this method, so we
# replace it by a method that delegates to portal classes
return self._folder.write(self.getId(), data, create=False) return self._folder.write(self.getId(), data, create=False)
def wl_lockmapping(self, killinvalids=0, create=0):
# We store web dav locks on portal classes itself
return self.aq_parent.aq_parent.wl_lockmapping(
killinvalids=killinvalids,
create=create)
InitializeClass(FileProxy) InitializeClass(FileProxy)
_MARKER = object() _MARKER = object()
...@@ -189,20 +198,28 @@ if allowClassTool(): ...@@ -189,20 +198,28 @@ if allowClassTool():
"""Proxy to a Folder """Proxy to a Folder
""" """
all_meta_types = () all_meta_types = ()
def __init__(self, id, reader, writer, lister, reset_on_write=True): def __init__(self, id, reader, writer, importer, lister):
self._setId(id) self._setId(id)
self.read = reader self.read = reader
self.__writer = writer self.__writer = writer
self.__importer = importer
self.__lister = lister self.__lister = lister
self.__reset_on_write = reset_on_write
def objectIds(self, spec=None): def objectIds(self, spec=None):
return self.__lister() return self.__lister()
def write(self, class_id, text, create=True): def write(self, class_id, text, create=True):
self.__writer(class_id, text, create=create) self.__writer(class_id, text, create=create)
if self.__reset_on_write: current_transaction = transaction.get()
_aq_reset() if hasattr(current_transaction, 'addAfterCommitHook'):
current_transaction.addAfterCommitHook(self.reimport, (class_id, ),)
else:
LOG('ClassTool', WARNING, 'Transaction does not support '
'addAfterCommitHook, code will not be reloaded')
def reimport(self, status, class_id):
if status and self.__importer is not None:
self.__importer(class_id)
def _getOb(self, key, default=_MARKER ): def _getOb(self, key, default=_MARKER ):
if key in self.objectIds(): if key in self.objectIds():
...@@ -216,13 +233,13 @@ if allowClassTool(): ...@@ -216,13 +233,13 @@ if allowClassTool():
raise AttributeError, key raise AttributeError, key
def PUT_factory(self, name, typ, body): def PUT_factory(self, name, typ, body):
self.write(name, body, create=True)
# store the information that this file has just been created, and cannot # store the information that this file has just been created, and cannot
# be read yet, because the transaction is not commited. # be read yet, because the transaction is not commited.
self._v_created = {name: True} self._v_created = {name: True}
self.write(name, body, create=True)
return self._getOb(name) return self._getOb(name)
def _verifyObjectPaste(self, ob, validate_src): def _verifyObjectPaste(self, ob, validate_src=True):
# we only allow FileProxy (this is used in PUT) # we only allow FileProxy (this is used in PUT)
if not isinstance(ob, FileProxy): if not isinstance(ob, FileProxy):
raise Unauthorized raise Unauthorized
...@@ -246,36 +263,44 @@ if allowClassTool(): ...@@ -246,36 +263,44 @@ if allowClassTool():
return ('PropertySheet', 'Document', 'Constraint', 'Extensions', 'tests') return ('PropertySheet', 'Document', 'Constraint', 'Extensions', 'tests')
def _getOb(self, key, default=_MARKER): def _getOb(self, key, default=_MARKER):
from Products.ERP5Type.Utils import importLocalPropertySheet
from Products.ERP5Type.Utils import importLocalDocument
from Products.ERP5Type.Utils import importLocalConstraint
if key == 'PropertySheet': if key == 'PropertySheet':
return FolderProxy('PropertySheet', return FolderProxy('PropertySheet',
reader=readLocalPropertySheet, reader=readLocalPropertySheet,
writer=self.writeLocalPropertySheet, writer=self.writeLocalPropertySheet,
importer=importLocalPropertySheet,
lister=getLocalPropertySheetList, lister=getLocalPropertySheetList,
reset_on_write=True).__of__(self) ).__of__(self)
if key == 'Document': if key == 'Document':
return FolderProxy('Document', return FolderProxy('Document',
reader=readLocalDocument, reader=readLocalDocument,
writer=self.writeLocalDocument, writer=self.writeLocalDocument,
importer=importLocalDocument,
lister=getLocalDocumentList, lister=getLocalDocumentList,
reset_on_write=True).__of__(self) ).__of__(self)
if key == 'Constraint': if key == 'Constraint':
return FolderProxy('Constraint', return FolderProxy('Constraint',
reader=readLocalConstraint, reader=readLocalConstraint,
writer=self.writeLocalConstraint, writer=self.writeLocalConstraint,
importer=importLocalConstraint,
lister=getLocalConstraintList, lister=getLocalConstraintList,
reset_on_write=True).__of__(self) ).__of__(self)
if key == 'Extensions': if key == 'Extensions':
return FolderProxy('Extensions', return FolderProxy('Extensions',
reader=readLocalExtension, reader=readLocalExtension,
writer=self.writeLocalExtension, writer=self.writeLocalExtension,
importer=None,
lister=getLocalExtensionList, lister=getLocalExtensionList,
reset_on_write=False).__of__(self) ).__of__(self)
if key == 'tests': if key == 'tests':
return FolderProxy('tests', return FolderProxy('tests',
reader=readLocalTest, reader=readLocalTest,
writer=self.writeLocalTest, writer=self.writeLocalTest,
importer=None,
lister=getLocalTestList, lister=getLocalTestList,
reset_on_write=False).__of__(self) ).__of__(self)
if default is not _MARKER: if default is not _MARKER:
return default return default
raise AttributeError, key raise AttributeError, key
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment