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 ):
from Products.ERP5Form.PreferenceTool import createPreferenceMethods
createPreferenceMethods(self.getPortalObject())
except ImportError, e :
LOG('Base._aq_dynamic', 100,
LOG('Base._aq_dynamic', WARNING,
'unable to create methods for PreferenceTool', e)
raise
Base.aq_preference_generated = 1
......@@ -797,10 +797,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
if hasattr(Base.aq_portal_type[self.portal_type], accessor_name):
method = getattr(self, accessor_name)
return method(**kw)
#elif hasattr(aq_self, key):
# value = getattr(aq_self, key)
# if callable(value): value = value()
# return value
else:
return ERP5PropertyManager.getProperty(self, key, d=d, **kw)
......@@ -825,7 +821,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
Generic accessor. Calls the real accessor
"""
self._setProperty(key,value,type=type, **kw)
self._setProperty(key,value, type=type, **kw)
self.reindexObject()
security.declareProtected( Permissions.ModifyPortalContent, '_setProperty' )
......@@ -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=))
"""
#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 in list_types: # Patch for OFS PropertyManager
key += '_list'
......@@ -848,21 +842,11 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
# since we will change the value on self
# rather than through implicit aquisition
if hasattr(aq_self, accessor_name):
#LOG("Calling: ",0, '%r %r ' % (accessor_name, key))
method = getattr(self, accessor_name)
method(value, **kw)
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)
if hasattr(aq_self, public_accessor_name):
#LOG("Calling: ",0, '%r %r ' % (public_accessor_name, key))
method = getattr(self, public_accessor_name)
method(value, **kw)
return
......@@ -898,21 +882,11 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
# since we will change the value on self
# rather than through implicit aquisition
if hasattr(aq_self, accessor_name):
#LOG("Calling: ",0, '%r %r ' % (accessor_name, key))
method = getattr(self, accessor_name)
method(value, **kw)
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)
if hasattr(aq_self, public_accessor_name):
#LOG("Calling: ",0, '%r %r ' % (public_accessor_name, key))
method = getattr(self, public_accessor_name)
method(value, **kw)
return
......@@ -990,32 +964,15 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
Each time attributes of an object are updated, they should
be updated through this generic edit method
"""
categoryIds = self._getCategoryTool().getBaseCategoryIds()
id_changed = 0
self._v_modified_property_dict = {}
for key in kw.keys():
#if key in categoryIds:
# self._setCategoryMembership(key, kw[key])
if key != 'id':
# We only change if the value is different
# This may be very long....
accessor_name = 'get' + UpperCase(key)
#LOG("Base_edit,key: ",0, key)
if force_update:
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
# This may be very long...
old_value = None
if not force_update:
old_value = self.getProperty(key)
if old_value != kw[key] or force_update:
# We keep in a thread var the previous values
# this can be useful for interaction workflow to implement lookups
......@@ -1185,8 +1142,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
WARNING : must be updates for circular references issues
"""
#if not hasattr(self, 'uid'):
# self.reindexObject()
uid = getattr(aq_base(self), 'uid', None)
if uid is None:
self.uid = self.portal_catalog.newUid()
......@@ -1964,20 +1919,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
# LOG('Base.setBinaryData',0,'data for : %s' % str(self))
# 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')
def commitTransaction(self):
# Commit a zope transaction (to reduce locks)
......@@ -1992,8 +1933,6 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
def __hash__(self):
return hash(self.getUid())
#psyco.bind(getObjectMenu)
security.declareProtected(Permissions.ModifyPortalContent, 'setGuid')
def setGuid(self):
"""
......@@ -2042,7 +1981,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
# Predicate handling
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
looking up methods named Class_asPredictae, MetaType_asPredicate, PortalType_asPredicate
......@@ -2063,7 +2002,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
def cashed_getAcquireLocalRoles(portal_type):
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())
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