Commit 865a8100 authored by Alexandre Boeglin's avatar Alexandre Boeglin

* _getDefaultAcquiredProperty: null_value is a list, return its first element

  instead of returning the list.
* getCompactTitle: look for a "getCompactTitle" type based method, and return
  its value if found.
* getCompactTranslatedTitle: same as getCompactTitle, but look for a
  "getTranslatedCompactTitle" type based method first.
* getIntId: if int conversion does not work in base 10, try in base 16.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19773 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2b0cd374
...@@ -1063,7 +1063,7 @@ class Base( CopyContainer, ...@@ -1063,7 +1063,7 @@ class Base( CopyContainer,
accessor_id, depends, storage_id, alt_accessor_id, is_list_type, is_tales_type, accessor_id, depends, storage_id, alt_accessor_id, is_list_type, is_tales_type,
checked_permission) checked_permission)
if acquisition_key in tv: if acquisition_key in tv:
return null_value return null_value[0]
tv[acquisition_key] = 1 tv[acquisition_key] = 1
...@@ -2388,19 +2388,24 @@ class Base( CopyContainer, ...@@ -2388,19 +2388,24 @@ class Base( CopyContainer,
'getCompactTitle') 'getCompactTitle')
def getCompactTitle(self): def getCompactTitle(self):
""" """
Returns the translated short title or the reference or Returns the first non-null value from the following:
the translated title or the ID by order of priority - "getCompactTitle" type based method
- short title
NOTE: It could be useful to make this method overridable - reference
with a type methode. - title
- id
""" """
method = self._getTypeBasedMethod('getCompactTitle')
if method is not None:
r = method()
if r: return r
if self.hasShortTitle(): if self.hasShortTitle():
r = self.getShortTitle() r = self.getShortTitle()
if r: return r if r: return r
if self.hasReference(): if self.hasReference():
r = self.getReference() r = self.getReference()
if r: return r if r: return r
r = self.getTitle() # No need to test existence since all Base instances have this method r = self._baseGetTitle() # No need to test existence since all Base instances have this method
if r: return r # Also useful whenever title is calculated if r: return r # Also useful whenever title is calculated
return self.getId() return self.getId()
...@@ -2408,12 +2413,24 @@ class Base( CopyContainer, ...@@ -2408,12 +2413,24 @@ class Base( CopyContainer,
'getCompactTranslatedTitle') 'getCompactTranslatedTitle')
def getCompactTranslatedTitle(self): def getCompactTranslatedTitle(self):
""" """
Returns the translated short title or the reference or Returns the first non-null value from the following:
the translated title or the ID by order of priority - "getTranslatedCompactTitle" type based method
- "getCompactTitle" type based method
NOTE: It could be useful to make this method overridable - translated short title
with a type methode. - short title
""" - reference
- translated title
- title
- id
"""
method = self._getTypeBasedMethod('getTranslatedCompactTitle')
if method is not None:
r = method()
if r: return r
method = self._getTypeBasedMethod('getCompactTitle')
if method is not None:
r = method()
if r: return r
if self.hasShortTitle(): if self.hasShortTitle():
r = self.getTranslatedShortTitle() r = self.getTranslatedShortTitle()
if r: return r if r: return r
...@@ -2422,7 +2439,7 @@ class Base( CopyContainer, ...@@ -2422,7 +2439,7 @@ class Base( CopyContainer,
if self.hasReference(): if self.hasReference():
r = self.getReference() r = self.getReference()
if r: return r if r: return r
r = self.getTranslatedTitle() # No need to test existence since all Base instances have this method r = self._baseGetTranslatedTitle() # No need to test existence since all Base instances have this method
if r: return r # Also useful whenever title is calculated if r: return r # Also useful whenever title is calculated
return self.getId() return self.getId()
...@@ -2430,7 +2447,11 @@ class Base( CopyContainer, ...@@ -2430,7 +2447,11 @@ class Base( CopyContainer,
security.declareProtected(Permissions.AccessContentsInformation, 'getIntId') security.declareProtected(Permissions.AccessContentsInformation, 'getIntId')
def getIntId(self): def getIntId(self):
try: try:
return int(self.getId()) id_string = self.getId()
return int(id_string)
except (ValueError, TypeError):
try:
return int(id_string, 16)
except (ValueError, TypeError): except (ValueError, TypeError):
return None return None
......
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