Commit 846ba5e6 authored by Jean-Paul Smets's avatar Jean-Paul Smets

The implementation of "Accessor overloading" was not done properly. First of...

The implementation of "Accessor overloading" was not done properly. First of all, there is no need to overload public setters, because the Alias.Reindex is able to use the private ones. So overloading the private ones is enough. Second, it is not appriopriate to reimplement the way data is set or accessed on objects. Instead of setting title with self.title = value, one should call self._baseSetTitle(value) which does much more, including casting data types and potentially storing values externally.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22573 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 69a28e4e
......@@ -120,51 +120,31 @@ class Person(XMLObject):
return ' '.join(name_list)
else:
return self.title
security.declareProtected(Permissions.AccessContentsInformation,
'title_or_id')
def title_or_id(self):
return self.getTitleOrId()
security.declareProtected(Permissions.ModifyPortalContent, 'setTitle')
def setTitle(self, value):
"""
Updates the title if necessary
"""
self._setTitle(value)
self.reindexObject()
def _setFirstName(self, value):
"""
Update Title if first_name is modified
"""
self.first_name = value
if self.getFirstName()!=None and self.getLastName()!=None:
self._setTitle(self.getFirstName()+' '+self.getLastName())
security.declareProtected(Permissions.ModifyPortalContent, 'setFirstName')
def setFirstName(self, value):
"""
Updates the first_name if necessary
"""
self._setFirstName(value)
self.reindexObject()
self._baseSetFirstName(value)
name_list = []
if self.getFirstName(): name_list.append(self.getFirstName())
if self.getLastName(): name_list.append(self.getLastName())
if name_list: self._setTitle(' '.join(name_list))
def _setLastName(self, value):
"""
Update Title if last_name is modified
"""
self.last_name = value
if self.getFirstName()!=None and self.getLastName()!=None:
self._setTitle(self.getFirstName()+' '+self.getLastName())
security.declareProtected(Permissions.ModifyPortalContent, 'setLastName')
def setLastName(self, value):
"""
Updates the last_name if necessary
"""
self._setLastName(value)
self.reindexObject()
self._baseSetLastName(value)
name_list = []
if self.getFirstName(): name_list.append(self.getFirstName())
if self.getLastName(): name_list.append(self.getLastName())
if name_list: self._setTitle(' '.join(name_list))
security.declareProtected('Manage users', 'setReference')
def setReference(self, value):
......@@ -203,7 +183,7 @@ class Person(XMLObject):
if value is not None :
return pw_validate(self.getPassword(), value)
return False
security.declarePublic('setPassword')
def setPassword(self, value) :
"""
......@@ -214,7 +194,7 @@ class Person(XMLObject):
raise AccessControl_Unauthorized('setPassword')
self._setPassword(pw_encrypt(value))
self.reindexObject()
# Time management
security.declareProtected(Permissions.AccessContentsInformation,
'getAvailableTime')
......
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