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

Use getProperty to check old value in edit. remove some commented out code

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6859 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ce90aa0d
...@@ -474,7 +474,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -474,7 +474,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
from Products.ERP5Form.PreferenceTool import createPreferenceMethods from Products.ERP5Form.PreferenceTool import createPreferenceMethods
createPreferenceMethods(self.getPortalObject()) createPreferenceMethods(self.getPortalObject())
except ImportError, e : except ImportError, e :
LOG('Base._aq_dynamic', 100, LOG('Base._aq_dynamic', WARNING,
'unable to create methods for PreferenceTool', e) 'unable to create methods for PreferenceTool', e)
raise raise
Base.aq_preference_generated = 1 Base.aq_preference_generated = 1
...@@ -797,10 +797,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -797,10 +797,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
if hasattr(Base.aq_portal_type[self.portal_type], accessor_name): if hasattr(Base.aq_portal_type[self.portal_type], accessor_name):
method = getattr(self, accessor_name) method = getattr(self, accessor_name)
return method(**kw) return method(**kw)
#elif hasattr(aq_self, key):
# value = getattr(aq_self, key)
# if callable(value): value = value()
# return value
else: else:
return ERP5PropertyManager.getProperty(self, key, d=d, **kw) return ERP5PropertyManager.getProperty(self, key, d=d, **kw)
...@@ -825,7 +821,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -825,7 +821,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
Generic accessor. Calls the real accessor Generic accessor. Calls the real accessor
""" """
self._setProperty(key,value,type=type, **kw) self._setProperty(key,value, type=type, **kw)
self.reindexObject() self.reindexObject()
security.declareProtected( Permissions.ModifyPortalContent, '_setProperty' ) security.declareProtected( Permissions.ModifyPortalContent, '_setProperty' )
...@@ -837,8 +833,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -837,8 +833,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
**kw allows to call setProperty as a generic setter (ex. setProperty(value_uid, portal_type=)) **kw allows to call setProperty as a generic setter (ex. setProperty(value_uid, portal_type=))
""" """
#LOG('_setProperty', 0, 'key = %r, value = %r, type = %r, kw = %r' % (key, value, type, kw))
#LOG('In _setProperty',0, str(key))
if type is not 'string': # Speed if type is not 'string': # Speed
if type in list_types: # Patch for OFS PropertyManager if type in list_types: # Patch for OFS PropertyManager
key += '_list' key += '_list'
...@@ -848,21 +842,11 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -848,21 +842,11 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
# since we will change the value on self # since we will change the value on self
# rather than through implicit aquisition # rather than through implicit aquisition
if hasattr(aq_self, accessor_name): if hasattr(aq_self, accessor_name):
#LOG("Calling: ",0, '%r %r ' % (accessor_name, key))
method = getattr(self, accessor_name) method = getattr(self, accessor_name)
method(value, **kw) method(value, **kw)
return return
"""# Make sure we change the default value again
# if it was provided at the same time
new_key = 'default_%s' % key
if kw.has_key(new_key):
accessor_name = '_set' + UpperCase(new_key)
if hasattr(self, accessor_name):
method = getattr(self, accessor_name)
method(kw[new_key])"""
public_accessor_name = 'set' + UpperCase(key) public_accessor_name = 'set' + UpperCase(key)
if hasattr(aq_self, public_accessor_name): if hasattr(aq_self, public_accessor_name):
#LOG("Calling: ",0, '%r %r ' % (public_accessor_name, key))
method = getattr(self, public_accessor_name) method = getattr(self, public_accessor_name)
method(value, **kw) method(value, **kw)
return return
...@@ -898,21 +882,11 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -898,21 +882,11 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
# since we will change the value on self # since we will change the value on self
# rather than through implicit aquisition # rather than through implicit aquisition
if hasattr(aq_self, accessor_name): if hasattr(aq_self, accessor_name):
#LOG("Calling: ",0, '%r %r ' % (accessor_name, key))
method = getattr(self, accessor_name) method = getattr(self, accessor_name)
method(value, **kw) method(value, **kw)
return return
"""# Make sure we change the default value again
# if it was provided at the same time
new_key = 'default_%s' % key
if kw.has_key(new_key):
accessor_name = '_set' + UpperCase(new_key)
if hasattr(self, accessor_name):
method = getattr(self, accessor_name)
method(kw[new_key])"""
public_accessor_name = 'set' + UpperCase(key) public_accessor_name = 'set' + UpperCase(key)
if hasattr(aq_self, public_accessor_name): if hasattr(aq_self, public_accessor_name):
#LOG("Calling: ",0, '%r %r ' % (public_accessor_name, key))
method = getattr(self, public_accessor_name) method = getattr(self, public_accessor_name)
method(value, **kw) method(value, **kw)
return return
...@@ -990,32 +964,15 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -990,32 +964,15 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
Each time attributes of an object are updated, they should Each time attributes of an object are updated, they should
be updated through this generic edit method be updated through this generic edit method
""" """
categoryIds = self._getCategoryTool().getBaseCategoryIds()
id_changed = 0
self._v_modified_property_dict = {} self._v_modified_property_dict = {}
for key in kw.keys(): for key in kw.keys():
#if key in categoryIds:
# self._setCategoryMembership(key, kw[key])
if key != 'id': if key != 'id':
# We only change if the value is different # We only change if the value is different
# This may be very long.... # This may be very long...
accessor_name = 'get' + UpperCase(key) old_value = None
#LOG("Base_edit,key: ",0, key) if not force_update:
if force_update: old_value = self.getProperty(key)
old_value = None
elif hasattr(self, accessor_name):
#LOG("Calling: ",0, accessor_name)
method = getattr(self, accessor_name)
#LOG("Calling: ",0, method.__class__)
try:
old_value = method() # XXX Why not use getProperty ???
except TypeError:
# Catch error generated by bad formed tales expression error
old_value = None
#LOG("Old value: ",0, str(old_value))
#LOG("New value: ",0, str(kw[key]))
else:
old_value = None
if old_value != kw[key] or force_update: if old_value != kw[key] or force_update:
# We keep in a thread var the previous values # We keep in a thread var the previous values
# this can be useful for interaction workflow to implement lookups # this can be useful for interaction workflow to implement lookups
...@@ -1185,8 +1142,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -1185,8 +1142,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
WARNING : must be updates for circular references issues WARNING : must be updates for circular references issues
""" """
#if not hasattr(self, 'uid'):
# self.reindexObject()
uid = getattr(aq_base(self), 'uid', None) uid = getattr(aq_base(self), 'uid', None)
if uid is None: if uid is None:
self.uid = self.portal_catalog.newUid() self.uid = self.portal_catalog.newUid()
...@@ -1964,20 +1919,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -1964,20 +1919,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
# LOG('Base.setBinaryData',0,'data for : %s' % str(self)) # LOG('Base.setBinaryData',0,'data for : %s' % str(self))
# self.data = data # self.data = data
#security.declareProtected(Permissions.View, 'getObjectMenu')
#def getObjectMenu(self, *args, **kw):
# absolute_url = self.absolute_url()
#
#" jump_menu = """<select name="jump_select" size="1" tal:attributes="onChange string:submitAction(this.form,'%s/doJump')">
# <option selected value="1" disabled>%s</option>
# <span tal:repeat="action jump_actions">
# <option value="1" tal:content="action/name"
# tal:attributes="value action/url">Saut</option>
# </span>
# </select>""" % (self.gettext('Jump...'), absolute_url, )
#
# pass
security.declarePublic('commitTransaction') security.declarePublic('commitTransaction')
def commitTransaction(self): def commitTransaction(self):
# Commit a zope transaction (to reduce locks) # Commit a zope transaction (to reduce locks)
...@@ -1992,8 +1933,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -1992,8 +1933,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
def __hash__(self): def __hash__(self):
return hash(self.getUid()) return hash(self.getUid())
#psyco.bind(getObjectMenu)
security.declareProtected(Permissions.ModifyPortalContent, 'setGuid') security.declareProtected(Permissions.ModifyPortalContent, 'setGuid')
def setGuid(self): def setGuid(self):
""" """
...@@ -2042,7 +1981,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -2042,7 +1981,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
# Predicate handling # Predicate handling
security.declareProtected(Permissions.AccessContentsInformation, 'asPredicate') security.declareProtected(Permissions.AccessContentsInformation, 'asPredicate')
def asPredicate(self,script_id=None): def asPredicate(self, script_id=None):
""" """
This method tries to convert the current Document into a predicate This method tries to convert the current Document into a predicate
looking up methods named Class_asPredictae, MetaType_asPredicate, PortalType_asPredicate looking up methods named Class_asPredictae, MetaType_asPredicate, PortalType_asPredicate
...@@ -2063,7 +2002,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -2063,7 +2002,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
def cashed_getAcquireLocalRoles(portal_type): def cashed_getAcquireLocalRoles(portal_type):
return self._getTypesTool()[self.getPortalType()].acquire_local_roles return self._getTypesTool()[self.getPortalType()].acquire_local_roles
cashed_getAcquireLocalRoles = CachingMethod(cashed_getAcquireLocalRoles, id='Base__getAcquireLocalRoles') cashed_getAcquireLocalRoles = CachingMethod(cashed_getAcquireLocalRoles,
id='Base__getAcquireLocalRoles')
return cashed_getAcquireLocalRoles(portal_type=self.getPortalType()) return cashed_getAcquireLocalRoles(portal_type=self.getPortalType())
security.declareProtected(Permissions.View, 'get_local_permissions') security.declareProtected(Permissions.View, 'get_local_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