Commit 0337971b authored by Yusei Tahara's avatar Yusei Tahara

Return default value if key does not exist. By Python language convention,

a method named getXXX should not raise an exception even if key does not exist.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25736 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e64c3596
...@@ -118,7 +118,7 @@ class WebSection(Domain, PermanentURLMixIn): ...@@ -118,7 +118,7 @@ class WebSection(Domain, PermanentURLMixIn):
return PermanentURLMixIn.__bobo_traverse__(self, request, name) return PermanentURLMixIn.__bobo_traverse__(self, request, name)
security.declareProtected(Permissions.AccessContentsInformation, 'getLayoutProperty') security.declareProtected(Permissions.AccessContentsInformation, 'getLayoutProperty')
def getLayoutProperty(self, key, d=MARKER): def getLayoutProperty(self, key, default=None):
""" """
A simple method to get a property of the current by A simple method to get a property of the current by
acquiring it from the current section or its parents. acquiring it from the current section or its parents.
...@@ -129,12 +129,7 @@ class WebSection(Domain, PermanentURLMixIn): ...@@ -129,12 +129,7 @@ class WebSection(Domain, PermanentURLMixIn):
if result is not MARKER and result: if result is not MARKER and result:
return result return result
section = section.aq_parent section = section.aq_parent
# No property was defined on children neither on web site return default
# If a default is provided, return it
# else raise
if d is not MARKER:
return d
raise AttributeError('Web Section %s has no layout property %s' % (self.getUrl(), key))
security.declareProtected(Permissions.AccessContentsInformation, 'getWebSectionValue') security.declareProtected(Permissions.AccessContentsInformation, 'getWebSectionValue')
def getWebSectionValue(self): def getWebSectionValue(self):
......
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