[Erp5-report] r10125 - in /erp5/trunk/products/ERP5Type: ./ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Sep 18 20:54:15 CEST 2006
Author: jp
Date: Mon Sep 18 20:54:12 2006
New Revision: 10125
URL: http://svn.erp5.org?rev=10125&view=rev
Log:
First working implementation of temporary sub content
Modified:
erp5/trunk/products/ERP5Type/Base.py
erp5/trunk/products/ERP5Type/ERP5Type.py
erp5/trunk/products/ERP5Type/Utils.py
erp5/trunk/products/ERP5Type/tests/testERP5Type.py
Modified: erp5/trunk/products/ERP5Type/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Base.py?rev=10125&r1=10124&r2=10125&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Base.py (original)
+++ erp5/trunk/products/ERP5Type/Base.py Mon Sep 18 20:54:12 2006
@@ -1852,8 +1852,11 @@
def isTempObject(self):
"""
Tells if an object is temporary or not
- """
- return self.reindexObject is self._temp_reindexObject
+
+ Implementation is based on the fact that reindexObject method is overloaded
+ for all TempObjects with the same dummy method
+ """
+ return self.reindexObject.im_func is self._temp_reindexObject.im_func
# Workflow Related Method
security.declarePublic('getWorkflowStateItemList')
Modified: erp5/trunk/products/ERP5Type/ERP5Type.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/ERP5Type.py?rev=10125&r1=10124&r2=10125&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/ERP5Type.py (original)
+++ erp5/trunk/products/ERP5Type/ERP5Type.py Mon Sep 18 20:54:12 2006
@@ -21,10 +21,10 @@
##############################################################################
from Globals import InitializeClass, DTMLFile
-from exceptions import AccessControl_Unauthorized
from AccessControl import ClassSecurityInfo, getSecurityManager
from Acquisition import aq_base, aq_inner, aq_parent
+import Products
import Products.CMFCore.TypesTool
from Products.CMFCore.TypesTool import TypeInformation
from Products.CMFCore.TypesTool import FactoryTypeInformation
@@ -34,6 +34,7 @@
from Products.CMFCore.ActionProviderBase import ActionProviderBase
from Products.CMFCore.utils import SimpleItemWithProperties
from Products.CMFCore.Expression import createExprContext
+from Products.CMFCore.exceptions import AccessControl_Unauthorized
from Products.ERP5Type import PropertySheet
from Products.ERP5Type import _dtmldir
from Products.ERP5Type import Permissions
@@ -183,8 +184,9 @@
self.getId())
p = container.manage_addProduct[self.product]
if hasattr(container, 'isTempObject') and container.isTempObject():
- factory_name = self.factory
- factory_name.replace('add', 'newTemp')
+ factory_name = self.factory.replace('add', 'newTemp') # We suppose here
+ # that methods are names addClass or newTempClass
+ # Prefix should be moved to a central place.
m = getattr(p, factory_name, None)
else:
m = getattr(p, self.factory, None)
@@ -233,8 +235,7 @@
Return list of content types.
XXX I (seb) think the name is bad
"""
- from Products.ERP5Type import PropertySheet
- result = PropertySheet.__dict__.keys()
+ result = Products.ERP5Type.PropertySheet.__dict__.keys()
result = filter(lambda k: not k.startswith('__'), result)
result.sort()
return result
@@ -265,8 +266,7 @@
security.declareProtected(Permissions.AccessContentsInformation,
'getConstraintList')
def getConstraintList( self ):
- from Products.ERP5Type import Constraint
- result = Constraint.__dict__.keys()
+ result = Products.ERP5Type.Constraint.__dict__.keys()
result = filter(lambda k: k != 'Constraint' and not k.startswith('__'),
result)
result.sort()
@@ -368,13 +368,12 @@
We do this by creating a temp object at the root of the portal
and invoking propertyMap
"""
- from Products.ERP5Type import Document
# Access the factory method for temp object by guessing it
# according to ERP5 naming conventions (not very nice)
factory_method_id = self.factory.replace('add', 'newTemp', 1)
if not factory_method_id.startswith('newTemp'):
raise
- factory_method = getattr(Document, factory_method_id)
+ factory_method = getattr(Products.ERP5Type.Document, factory_method_id)
id = "some_very_unlikely_temp_object_id_which_should_not_exist"
portal = self.portal_url.getPortalObject()
portal_ids = portal.objectIds()
Modified: erp5/trunk/products/ERP5Type/Utils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Utils.py?rev=10125&r1=10124&r2=10125&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Utils.py (original)
+++ erp5/trunk/products/ERP5Type/Utils.py Mon Sep 18 20:54:12 2006
@@ -351,9 +351,13 @@
for k in ('isIndexable', 'reindexObject', 'recursiveReindexObject',
'activate', 'setUid', 'setTitle', 'getTitle'):
setattr(o, k, getattr(o,"_temp_%s" % k))
- o = o.__of__(folder)
if kw:
o.__of__(folder)._edit(force_update=1, **kw)
+ if folder.isTempObject(): # Temp Object in Temp Object should use containment
+ folder._setObject(id, o)
+ return id # return id to be compatible with CMF constructInstance
+ else: # Temp Object in Persistent Object should use acquisition
+ o = o.__of__(folder)
return o
@@ -685,7 +689,7 @@
temp_document_constructor_name,
temp_document_constructor)
ModuleSecurityInfo('Products.ERP5Type.Document').declarePublic(
- temp_document_constructor_name,)
+ temp_document_constructor_name,) # XXX Probably bad security
# Update Meta Types
new_meta_types = []
@@ -713,12 +717,14 @@
constructors = ( manage_addContentForm
, manage_addContent
, document_constructor
+ , temp_document_constructor
, ('factory_type_information',
document_class.factory_type_information) )
else:
constructors = ( manage_addContentForm
, manage_addContent
- , document_constructor )
+ , document_constructor
+ , temp_document_constructor )
initial = constructors[0]
m[initial.__name__]=manage_addContentForm
default_permission = ('Manager',)
Modified: erp5/trunk/products/ERP5Type/tests/testERP5Type.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testERP5Type.py?rev=10125&r1=10124&r2=10125&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testERP5Type.py (original)
+++ erp5/trunk/products/ERP5Type/tests/testERP5Type.py Mon Sep 18 20:54:12 2006
@@ -150,6 +150,13 @@
o.edit(tata=123)
self.assertEquals(o.getProperty('tata'), 123)
+ # Make sure this is a Temp Object
+ self.assertEquals(o.isTempObject(), 1)
+
+ # Create a subobject and make sure it is a Temp Object
+ a = o.newContent(portal_type = 'Telephone')
+ self.assertEquals(a.isTempObject(), 1)
+
def test_04_CategoryAccessors(self, quiet=quiet, run=run_all_test):
"""
This test provides basic testing of category
More information about the Erp5-report
mailing list