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
No related merge requests found
...@@ -126,45 +126,25 @@ class Person(XMLObject): ...@@ -126,45 +126,25 @@ class Person(XMLObject):
def title_or_id(self): def title_or_id(self):
return self.getTitleOrId() 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): def _setFirstName(self, value):
""" """
Update Title if first_name is modified Update Title if first_name is modified
""" """
self.first_name = value self._baseSetFirstName(value)
if self.getFirstName()!=None and self.getLastName()!=None: name_list = []
self._setTitle(self.getFirstName()+' '+self.getLastName()) if self.getFirstName(): name_list.append(self.getFirstName())
if self.getLastName(): name_list.append(self.getLastName())
security.declareProtected(Permissions.ModifyPortalContent, 'setFirstName') if name_list: self._setTitle(' '.join(name_list))
def setFirstName(self, value):
"""
Updates the first_name if necessary
"""
self._setFirstName(value)
self.reindexObject()
def _setLastName(self, value): def _setLastName(self, value):
""" """
Update Title if last_name is modified Update Title if last_name is modified
""" """
self.last_name = value self._baseSetLastName(value)
if self.getFirstName()!=None and self.getLastName()!=None: name_list = []
self._setTitle(self.getFirstName()+' '+self.getLastName()) if self.getFirstName(): name_list.append(self.getFirstName())
if self.getLastName(): name_list.append(self.getLastName())
security.declareProtected(Permissions.ModifyPortalContent, 'setLastName') if name_list: self._setTitle(' '.join(name_list))
def setLastName(self, value):
"""
Updates the last_name if necessary
"""
self._setLastName(value)
self.reindexObject()
security.declareProtected('Manage users', 'setReference') security.declareProtected('Manage users', 'setReference')
def setReference(self, value): def setReference(self, value):
......
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