Commit dc241f2a authored by Jim Fulton's avatar Jim Fulton

Changed to use new object management hooks.

parent 152645d3
......@@ -84,7 +84,7 @@
##############################################################################
"""Access control package"""
__version__='$Revision: 1.79 $'[11:-2]
__version__='$Revision: 1.80 $'[11:-2]
import Globals, App.Undo, socket, regex
from Globals import HTMLFile, MessageDialog, Persistent, PersistentMapping
......@@ -596,17 +596,15 @@ class BasicUserFolder(Implicit, Persistent, Navigation, Tabs, RoleManager,
def user_names(self):
return self.getUserNames()
# Copy/Paste support
def manage_beforeDelete(self, item, container):
if item is self:
try: del container.__allow_groups__
except: pass
def _notifyOfCopyTo(self, container, op=0):
if hasattr(container, 'aq_base'):
container=container.aq_base
if hasattr(container, 'acl_users'):
raise TypeError, (
'Target already contains a UserFolder.')
def _postCopy(self, container, op=0):
container.__allow_groups__=container.acl_users
def manage_afterAdd(self, item, container):
if item is self:
if hasattr(self, 'aq_base'): self=self.aq_base
container.__allow_groups__=self
def _setId(self, id):
if id != self.id:
......
......@@ -84,10 +84,11 @@
##############################################################################
__doc__='''Principia Factories
$Id: Factory.py,v 1.10 1999/06/16 14:15:27 brian Exp $'''
__version__='$Revision: 1.10 $'[11:-2]
$Id: Factory.py,v 1.11 1999/06/24 19:24:55 jim Exp $'''
__version__='$Revision: 1.11 $'[11:-2]
import OFS.SimpleItem, Acquisition, Globals
import Product
class Factory(Globals.Persistent, Acquisition.Implicit, OFS.SimpleItem.Item):
"Model factory meta-data"
......@@ -101,12 +102,13 @@ class Factory(Globals.Persistent, Acquisition.Implicit, OFS.SimpleItem.Item):
{'label':'Security', 'action':'manage_access'},
)
def __init__(self, id, title, object_type, initial, product):
def __init__(self, id, title, object_type, initial, product=None):
self.id=id
self.title=title
self.object_type=object_type
self.initial=initial
self.__of__(product)._register()
if product is not None:
self.__of__(product)._register()
def manage_edit(self, title, object_type, initial, REQUEST=None):
"Modify factory properties."
......@@ -117,13 +119,23 @@ class Factory(Globals.Persistent, Acquisition.Implicit, OFS.SimpleItem.Item):
self._register()
if REQUEST is not None: return self.manage_main(self, REQUEST)
def _notifyOfCopyTo(self, container, op=0):
if container.__class__ is not Product:
raise TypeError, (
'Factories can only be copied to <b>products</b>.')
def manage_afterAdd(self, item, container):
if hasattr(self, 'aq_parent'):
container=self.aq_parent
elif item is not self:
container=None
def _postCopy(self, container, op=0):
self._register()
if getattr(container, '__class__', None) is Product.Product:
self._register()
def manage_beforeDelete(self, item, container):
if hasattr(self, 'aq_parent'):
container=self.aq_parent
elif item is not self:
container=None
if getattr(container, '__class__', None) is Product.Product:
self._unregister()
def _register(self):
# Register with the product folder
......@@ -137,7 +149,6 @@ class Factory(Globals.Persistent, Acquisition.Implicit, OFS.SimpleItem.Item):
product.aq_acquire('_manage_remove_product_meta_type')(
product, self.id, self.object_type)
manage_main=Globals.HTMLFile('editFactory',globals())
def index_html(self, REQUEST):
......
......@@ -111,7 +111,7 @@ from OFS.Folder import Folder
import regex, zlib, Globals, cPickle, marshal, rotor
from string import rfind, atoi, find, strip, join
from Factory import Factory
import ZClasses
import ZClasses, ZClasses.ZClass
class ProductFolder(Folder):
"Manage a collection of Products"
......@@ -142,13 +142,6 @@ class ProductFolder(Folder):
if REQUEST is not None:
return self.manage_main(self,REQUEST,update_menu=1)
def _delObject(self,id):
try:
for factory in getattr(self, id)._factories():
factory._unregister()
except: pass
ProductFolder.inheritedAttribute('_delObject')(self, id)
def _canCopy(self, op=0):
return 0
......@@ -206,39 +199,15 @@ class Product(Folder):
def manage_addPrincipiaFactory(
self, id, title, object_type, initial, REQUEST=None):
' '
i=Factory(id, title, object_type, initial, self)
i=Factory(id, title, object_type, initial)
self._setObject(id,i)
if REQUEST is not None:
return self.manage_main(self,REQUEST,update_menu=1)
def _delObject(self,id, dp=1):
o=getattr(self, id)
if o.meta_type==Factory.meta_type: o._unregister()
Product.inheritedAttribute('_delObject')(self, id, dp=1)
def __init__(self, id, title):
self.id=id
self.title=title
def _notifyOfCopyTo(self, container, op=0):
if container.__class__ is not ProductFolder:
raise TypeError, (
'Products can only be copied to <b>product folders</b>.')
def _postCopy(self, container, op=0):
for factory in self._factories():
factory._register()
def _factories(self):
r=[]
append=r.append
for o in self.__dict__.values():
if hasattr(o,'meta_type') and o.meta_type==Factory.meta_type:
append(o.__of__(self))
return r
def Destination(self):
"Return the destination for factory output"
return self
......@@ -440,8 +409,12 @@ def initializeProduct(productp, name, home, app):
if old is not None:
app._manage_remove_product_meta_type(product)
products._delObject(name)
for id, v in old.objectValues():
try: product._setObject(id, v)
except: pass
products._setObject(name, product)
product.__of__(products)._postCopy(products)
#product.__of__(products)._postCopy(products)
product.manage_options=Folder.manage_options
product.icon='p_/InstalledProduct_icon'
product.version=fver
......
......@@ -83,7 +83,7 @@
#
##############################################################################
__doc__="""Copy interface"""
__version__='$Revision: 1.35 $'[11:-2]
__version__='$Revision: 1.36 $'[11:-2]
import sys, string, Globals, Moniker, tempfile, ExtensionClass
from marshal import loads, dumps
......@@ -183,24 +183,25 @@ class CopyContainer(ExtensionClass.Base):
try: ob=m.bind()
except: raise CopyError, eNotFound
self._verifyObjectPaste(ob, REQUEST)
try: ob._notifyOfCopyTo(self, op=op)
except: raise CopyError, MessageDialog(
title='Copy Error',
message=sys.exc_value,
action ='manage_main')
# try: ob._notifyOfCopyTo(self, op=op)
# except: raise CopyError, MessageDialog(
# title='Copy Error',
# message=sys.exc_value,
# action ='manage_main')
oblist.append(ob)
if op==0:
# Copy operation
for ob in oblist:
if not ob.cb_isCopyable():
raise CopyError, eNotSupported % absattr(ob.id)
raise CopyError, eNotSupported % absattr(ob.id)
ob=ob._getCopy(self)
ob.manage_afterClone(ob)
id=_get_id(self, absattr(ob.id))
ob._setId(id)
self._setObject(id, ob)
ob=ob.__of__(self)
ob._postCopy(self, op=0)
#ob=ob.__of__(self)
#ob._postCopy(self, op=0)
if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=1,
......@@ -218,8 +219,8 @@ class CopyContainer(ExtensionClass.Base):
id=_get_id(self, id)
ob._setId(id)
self._setObject(id, ob)
ob=ob.__of__(self)
ob._postCopy(self, op=1)
#ob=ob.__of__(self)
#ob._postCopy(self, op=1)
if REQUEST is not None:
REQUEST['RESPONSE'].setCookie('cp_', 'deleted',
......@@ -251,10 +252,10 @@ class CopyContainer(ExtensionClass.Base):
self._delObject(id, dp=0)
if hasattr(ob, 'aq_base'):
ob=ob.aq_base
self._setObject(new_id, ob)
ob=ob.__of__(self)
ob._setId(new_id)
ob._postCopy(self, op=1)
self._setObject(new_id, ob)
#ob=ob.__of__(self)
#ob._postCopy(self, op=1)
if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=1)
return None
......@@ -282,8 +283,8 @@ class CopyContainer(ExtensionClass.Base):
ob=ob._getCopy(self)
ob._setId(id)
self._setObject(id, ob)
ob=ob.__of__(self)
ob._postCopy(self, op=0)
#ob=ob.__of__(self)
#ob._postCopy(self, op=0)
return ob
def cb_dataValid(self):
......
......@@ -84,9 +84,9 @@
##############################################################################
__doc__="""Object Manager
$Id: ObjectManager.py,v 1.73 1999/06/18 00:32:39 amos Exp $"""
$Id: ObjectManager.py,v 1.74 1999/06/24 19:27:16 jim Exp $"""
__version__='$Revision: 1.73 $'[11:-2]
__version__='$Revision: 1.74 $'[11:-2]
import App.Management, Acquisition, App.Undo, Globals, CopySupport
import os, App.FactoryDispatcher, ts_regex, Products
......@@ -205,6 +205,8 @@ class ObjectManager(
except: t=None
self._objects=self._objects+({'id':id,'meta_type':t},)
self._setOb(id,object)
object=self._getOb(id)
object.manage_afterAdd(object, self)
# Try to give user the local role "Owner".
if hasattr(self, 'REQUEST') and hasattr(object, '__ac_local_roles__'):
user=self.REQUEST['AUTHENTICATED_USER']
......@@ -213,28 +215,30 @@ class ObjectManager(
object.manage_setLocalRoles(name, ['Owner'])
return id
def manage_afterAdd(self, item, container):
for object in self.objectValues():
try: s=object._p_changed
except: s=0
object.manage_afterAdd(item, container)
if s is None: object._p_deactivate()
def manage_afterClone(self, item):
for object in self.objectValues():
try: s=object._p_changed
except: s=0
object.manage_afterClone(item)
if s is None: object._p_deactivate()
def manage_beforeDelete(self, item, container):
for object in self.objectValues():
try: s=object._p_changed
except: s=0
object.manage_beforeDelete(item, container)
if s is None: object._p_deactivate()
def _delObject(self, id, dp=1):
if id=='acl_users':
# Yikes - acl_users is referred to by two names and
# must be treated as a special case! Only get rid of
# __allow_groups__ if it is an instance attribute, to
# avoid deleting the class-default __allow_groups__
# in the top-level application object which is needed
# to allow people to replace the top-level userfolder.
if hasattr(self, '__allow_groups__') and \
self.__dict__.has_key('__allow_groups__'):
delattr(self, '__allow_groups__')
# Deletion protocol - when an object is being deleted,
# attempt to call it's _on_delete_object method if
# if has one. The dp flag allows allows callers to
# avoid having the delete protocol triggered (for
# instance when an object is cut and pasted).
if dp:
ob=self._getOb(id)
if hasattr(ob, '_on_delete_object') and \
callable(ob._on_delete_object):
ob._on_delete_object()
del ob
object=self._getOb(id)
object.manage_beforeDelete(object, self)
self._objects=tuple(filter(lambda i,n=id: i['id']!=n, self._objects))
self._delOb(id)
......
......@@ -89,8 +89,8 @@ Aqueduct database adapters, etc.
This module can also be used as a simple template for implementing new
item types.
$Id: SimpleItem.py,v 1.58 1999/06/23 15:27:01 jim Exp $'''
__version__='$Revision: 1.58 $'[11:-2]
$Id: SimpleItem.py,v 1.59 1999/06/24 19:27:25 jim Exp $'''
__version__='$Revision: 1.59 $'[11:-2]
import regex, sys, Globals, App.Management, Acquisition
from webdav.Resource import Resource
......@@ -111,13 +111,9 @@ class Item(Base, Resource, CopySource, App.Management.Tabs):
isPrincipiaFolderish=0
isTopLevelPrincipiaApplicationObject=0
# HACK HACK HACK -- TAKE THIS OUT LATER!!!!
def _on_delete_object(self):
if hasattr(self, 'onDeleteObject') and \
callable(self.onDeleteObject):
self.onDeleteObject()
def manage_afterAdd(self, item, container): pass
def manage_beforeDelete(self, item, container): pass
def manage_afterClone(self, item): pass
# The name of this object and the name used to traverse to thie
# object in a URL:
......
......@@ -207,25 +207,18 @@ class Draft(Persistent, Implicit, SimpleItem.Item):
if REQUEST:
REQUEST['RESPONSE'].redirect(REQUEST['URL2']+'/manage_main')
def _notifyOfCopyTo(self, container, isMove=0):
if isMove and self.nonempty():
raise 'Copy Error', (
"You cannot copy a %s object with <b>unapproved</b> changes.\n"
"You must <b>approve</b> the changes first."
% self.meta_type)
def _postCopy(self, container, op=0):
try:
version=self.REQUEST['PATH_INFO']
l=rfind(version,'/')
if l >= 0: version=version[:l]
self._version="%s/%s" % (version, self.id)
finally:
if 0:
raise 'Copy Error', (
"This object can only be copied through the web.<p>")
def manage_afterClone(self, item):
self._version=''
def manage_afterAdd(self, item, container):
if not self._version:
self._version=self.absolute_url(1)
def manage_beforeDelete(self, item, container):
if self._nonempty():
raise 'Version Error', (
'Attempt to %sdelete a non-empty version.<p>'
((self is not item) and 'indirectly ' or ''))
Globals.default__class_init__(Draft)
......
......@@ -84,7 +84,7 @@
##############################################################################
"""Version object"""
__version__='$Revision: 1.32 $'[11:-2]
__version__='$Revision: 1.33 $'[11:-2]
import Globals, time
from AccessControl.Role import RoleManager
......@@ -100,10 +100,11 @@ manage_addVersionForm=Globals.HTMLFile('versionAdd', globals())
def manage_addVersion(self, id, title, REQUEST=None):
""" """
self._setObject(id, Version(id,title,self,REQUEST))
return self.manage_main(self,REQUEST)
self=self.this()
self._setObject(id, Version(id,title,REQUEST))
if REQUEST is not None:
REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')
class Version(Persistent,Implicit,RoleManager,Item):
""" """
......@@ -121,12 +122,11 @@ class Version(Persistent,Implicit,RoleManager,Item):
('Save/discard Version changes', ('save','discard')),
)
def __init__(self, id, title, parent, REQUEST):
cookie=''
def __init__(self, id, title, REQUEST):
self.id=id
self.title=title
try: parent=parent.Destination()
except: pass
self.cookie=self.__of__(parent).absolute_url(1)
manage=manage_main=Globals.HTMLFile('version', globals())
manage_editForm =Globals.HTMLFile('versionEdit', globals())
......@@ -230,11 +230,17 @@ class Version(Persistent,Implicit,RoleManager,Item):
# ZODB 3
return not db.versionEmpty(self.cookie)
def _notifyOfCopyTo(self, container, isMove=0):
if isMove and self.nonempty():
raise 'Copy Error', (
"You cannot copy a %s object with <b>unsaved</b> changes.\n"
"You must <b>save</b> the changes first."
% self.meta_type)
def manage_afterClone(self, item):
self.cookie=''
def manage_afterAdd(self, item, container):
if not self.cookie:
self.cookie=self.absolute_url(1)
def manage_beforeDelete(self, item, container):
if self._nonempty():
raise 'Version Error', (
'Attempt to %sdelete a non-empty version.<p>'
((self is not item) and 'indirectly ' or ''))
......@@ -221,9 +221,10 @@ class ZCommonSheet(OFS.PropertySheets.PropertySheet, OFS.SimpleItem.Item):
return ''
def _on_delete_object(self):
for d in self._properties:
self.delClassAttr(d['id'])
def manage_beforeDelete(self, item, container):
if self is item:
for d in self._properties:
self.delClassAttr(d['id'])
def manage_createEditor(self, id, title='', REQUEST=None):
"""Create an edit interface for a property sheet
......@@ -305,7 +306,7 @@ class ZInstanceSheet(OFS.PropertySheets.FixedSchema,
):
"Waaa this is too hard"
_Manage_properties_Permission=''
_Manage_properties_Permission='Manage properties'
_Access_contents_information_Permission='View'
__ac_permissions__=(
......
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