Commit 94cf3831 authored by Jean-Paul Smets's avatar Jean-Paul Smets

A few changes related to WebSection support + keep_existing property in edit...

A few changes related to WebSection support + keep_existing property in edit (although I am not sure if this should be kept)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11912 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b3f6a829
...@@ -992,7 +992,24 @@ class Base( CopyContainer, ...@@ -992,7 +992,24 @@ class Base( CopyContainer,
Previous Name: hasValue Previous Name: hasValue
Generic accessor. Calls the real accessor Generic accessor. Calls the real accessor
and returns 0 if it fails and returns 0 if it fails.
The idea of hasProperty is to call the tester methods.
It will return True only if a property was defined on the object.
(either by calling a Tester accessor or by checking if a local
property was added).
It will return False if the property is not part of the list
of valid properties (ie. the list of properties defined in
PropertySheets) or if the property has never been updated.
NOTE - One possible issue in the current implementation is that a
property which is set to its default value will be considered
as not being defined.
Ex. self.hasProperty('first_name') on a Person object
returns False if the first name was never defined and
even if self.getProperty('first_name') returns ''
""" """
accessor_name = 'has' + UpperCase(key) accessor_name = 'has' + UpperCase(key)
if hasattr(self, accessor_name): if hasattr(self, accessor_name):
...@@ -1004,6 +1021,7 @@ class Base( CopyContainer, ...@@ -1004,6 +1021,7 @@ class Base( CopyContainer,
except: except:
return 0 return 0
else: else:
# Check in local properties (which obviously were defined at some point)
for p_id in self.propertyIds(): for p_id in self.propertyIds():
if key==p_id: if key==p_id:
return 1 return 1
...@@ -1029,7 +1047,7 @@ class Base( CopyContainer, ...@@ -1029,7 +1047,7 @@ class Base( CopyContainer,
# Object attributes update method # Object attributes update method
security.declarePrivate( '_edit' ) security.declarePrivate( '_edit' )
def _edit(self, REQUEST=None, force_update=0, reindex_object=0, **kw): def _edit(self, REQUEST=None, force_update=0, reindex_object=0, keep_existing=0, **kw):
""" """
Generic edit Method for all ERP5 object Generic edit Method for all ERP5 object
The purpose of this method is to update attributed, eventually do The purpose of this method is to update attributed, eventually do
...@@ -1040,7 +1058,10 @@ class Base( CopyContainer, ...@@ -1040,7 +1058,10 @@ class Base( CopyContainer,
be updated through this generic edit method be updated through this generic edit method
Modification date is supported by edit_workflow in ERP5 Modification date is supported by edit_workflow in ERP5
There is no need to change it here There is no need to change it here.
keep_existing -- if set to 1 or True, only those properties for which
hasProperty is False will be updated.
""" """
self._v_modified_property_dict = {} self._v_modified_property_dict = {}
...@@ -1061,6 +1082,8 @@ class Base( CopyContainer, ...@@ -1061,6 +1082,8 @@ class Base( CopyContainer,
# this can be useful for interaction workflow to implement lookups # this can be useful for interaction workflow to implement lookups
# XXX If iteraction workflow script is triggered by edit and calls # XXX If iteraction workflow script is triggered by edit and calls
# edit itself, this is useless as the dict will be overwritten # edit itself, this is useless as the dict will be overwritten
# If the keep_existing flag is set to 1, we do not update properties which are defined
if not keep_existing or not self.hasProperty(key):
self._v_modified_property_dict[key] = old_value self._v_modified_property_dict[key] = old_value
my_modified_property_list.append(key) my_modified_property_list.append(key)
return my_modified_property_list return my_modified_property_list
...@@ -1291,7 +1314,7 @@ class Base( CopyContainer, ...@@ -1291,7 +1314,7 @@ class Base( CopyContainer,
security.declareProtected(Permissions.AccessContentsInformation, 'getRelativeUrl') security.declareProtected(Permissions.AccessContentsInformation, 'getRelativeUrl')
def getRelativeUrl(self): def getRelativeUrl(self):
""" """
Returns the absolute path of an object Returns the url of an object relative to the portal site.
""" """
return self.portal_url.getRelativeUrl(self) return self.portal_url.getRelativeUrl(self)
...@@ -2161,7 +2184,7 @@ class Base( CopyContainer, ...@@ -2161,7 +2184,7 @@ class Base( CopyContainer,
# Type Casting # Type Casting
security.declarePrivate( '_getTypeBasedMethod' ) security.declarePrivate( '_getTypeBasedMethod' )
def _getTypeBasedMethod(self, method_id, script_id=None): def _getTypeBasedMethod(self, method_id, fallback_script_id=None):
""" """
Looks up for Looks up for
""" """
...@@ -2171,14 +2194,13 @@ class Base( CopyContainer, ...@@ -2171,14 +2194,13 @@ class Base( CopyContainer,
script_name_end = '_%s' % method_id script_name_end = '_%s' % method_id
# Look at a local script which # Look at a local script which
# can return a new predicate. # can return a new predicate.
if script_id is not None:
script = getattr(self, script_id)
else:
for script_name_begin in [self.getPortalType(), self.getMetaType(), self.__class__.__name__]: for script_name_begin in [self.getPortalType(), self.getMetaType(), self.__class__.__name__]:
script_name = join([script_name_begin.replace(' ',''), script_name_end ], '') script_name = join([script_name_begin.replace(' ',''), script_name_end ], '')
if hasattr(self, script_name): if hasattr(self, script_name):
script = getattr(self, script_name) script = getattr(self, script_name)
break break
if script is None and fallback_script_id is not None:
script = getattr(self, fallback_script_id)
return script return script
# Predicate handling # Predicate handling
...@@ -2380,23 +2402,16 @@ class Base( CopyContainer, ...@@ -2380,23 +2402,16 @@ class Base( CopyContainer,
security.declareProtected(Permissions.AccessContentsInformation, 'getApplicableLayout') security.declareProtected(Permissions.AccessContentsInformation, 'getApplicableLayout')
def getApplicableLayout(self): def getApplicableLayout(self):
""" """
Return applicable layout in this acquisition context by The application layout of a standard document in the content layout.
browsing context parents.
However, if we are displaying a Web Section as its default document,
We have to take into account context before containment. This we should use the container layout.
is why standard acquisition must be circumvented here. """
""" try:
current = self if self.REQUEST.get('is_web_section_default_document', None):
# First try to get a container layout return self.REQUEST.get('current_web_section').getContainerLayout()
if hasattr(current, 'getContainerLayout') and current.getContainerLayout() not in ('', None): return self.getContentLayout() or self.getContainerLayout()
return current.getContainerLayout() except AttributeError:
# First try to get a content layout
while current is not None:
if hasattr(current, 'getContentLayout') and current.getContentLayout() not in ('', None):
return current.getContentLayout()
current = current.getParentValue()
if not hasattr(current, 'getApplicableLayout'):
return None
return None return None
security.declareProtected(Permissions.ChangeLocalRoles, security.declareProtected(Permissions.ChangeLocalRoles,
...@@ -2750,20 +2765,6 @@ class Base( CopyContainer, ...@@ -2750,20 +2765,6 @@ class Base( CopyContainer,
dochelper.setDynamicPropertyList(dynamic_property_list) dochelper.setDynamicPropertyList(dynamic_property_list)
return dochelper return dochelper
security.declareProtected(Permissions.AccessContentsInformation, 'getWebSectionValue')
def getWebSectionValue(self):
"""
Returns the current web section (ie. self) though parent acquisition
This method has been moved temporatily from WebSection to Base
until we understand the bug / issue in acquisition
"""
section = self
portal = self.getPortalObject()
while section.getPortalType() not in ('Web Site', 'Web Section', ) and\
section is not portal:
section = section.aq_parent
return section
InitializeClass(Base) InitializeClass(Base)
class TempBase(Base): class TempBase(Base):
......
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