Commit 3bdb9b3a authored by Jean-Paul Smets's avatar Jean-Paul Smets

Added getCompactTitle support (as well as getCompactLogicalPath) which is...

Added getCompactTitle support (as well as getCompactLogicalPath) which is useful for sites were the depth of categories in large. Actually, this should be teh standard default everywhere. Also added some aggressive caching. Still to be discussed if it is that good or not.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13198 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 315e570d
...@@ -31,12 +31,16 @@ import string ...@@ -31,12 +31,16 @@ import string
from Globals import InitializeClass, DTMLFile from Globals import InitializeClass, DTMLFile
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Acquisition import aq_base, aq_inner, aq_parent from Acquisition import aq_base, aq_inner, aq_parent
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type import PropertySheet from Products.ERP5Type import PropertySheet
from Products.ERP5Type.Core.Folder import Folder from Products.ERP5Type.Core.Folder import Folder
from Products.CMFCategory.Renderer import Renderer from Products.CMFCategory.Renderer import Renderer
from Products.ERP5Type.Utils import sortValueList from Products.ERP5Type.Utils import sortValueList
from Products.ERP5Type.Cache import CachingMethod
DEFAULT_CACHE_FACTORY = 'erp5_ui_long'
from zLOG import LOG from zLOG import LOG
...@@ -176,6 +180,12 @@ class Category(Folder): ...@@ -176,6 +180,12 @@ class Category(Folder):
""" """
return self.getLogicalPath(item_method='getTranslatedTitle') return self.getLogicalPath(item_method='getTranslatedTitle')
def getCompactLogicalPath(self):
"""
Returns compact logical path, started under base category.
"""
return self.getLogicalPath(item_method='getCompactTitle')
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getIndentedTitle') 'getIndentedTitle')
def getIndentedTitle(self): def getIndentedTitle(self):
...@@ -278,7 +288,7 @@ class Category(Folder): ...@@ -278,7 +288,7 @@ class Category(Folder):
def getCategoryChildTranslatedTitleItemList(self, recursive=1, base=0, **kw): def getCategoryChildTranslatedTitleItemList(self, recursive=1, base=0, **kw):
""" """
Returns a list of tuples by parsing recursively all categories in a Returns a list of tuples by parsing recursively all categories in a
given list of base categories. Uses getTitle as default method given list of base categories. Uses getTranslatedTitle as default method
""" """
return self.getCategoryChildItemList(recursive=recursive, return self.getCategoryChildItemList(recursive=recursive,
display_id='translated_title', base=base, **kw) display_id='translated_title', base=base, **kw)
...@@ -302,6 +312,16 @@ class Category(Folder): ...@@ -302,6 +312,16 @@ class Category(Folder):
return self.getCategoryChildItemList(recursive=recursive, return self.getCategoryChildItemList(recursive=recursive,
display_id='title_and_id', base=base, **kw) display_id='title_and_id', base=base, **kw)
security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildCompactTitleItemList')
def getCategoryChildCompactTitleItemList(self, recursive=1, base=0, **kw):
"""
Returns a list of tuples by parsing recursively all categories in a
given list of base categories. Uses title_and_id as default method
"""
return self.getCategoryChildItemList(recursive=recursive,
display_id='compact_title', base=base, **kw)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildLogicalPathItemList') 'getCategoryChildLogicalPathItemList')
def getCategoryChildLogicalPathItemList(self, recursive=1, base=0, **kw): def getCategoryChildLogicalPathItemList(self, recursive=1, base=0, **kw):
...@@ -320,6 +340,15 @@ class Category(Folder): ...@@ -320,6 +340,15 @@ class Category(Folder):
return self.getCategoryChildItemList(recursive=recursive, return self.getCategoryChildItemList(recursive=recursive,
display_id='translated_logical_path', base=base, **kw) display_id='translated_logical_path', base=base, **kw)
security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildCompactLogicalPathItemList')
def getCategoryChildCompactLogicalPathItemList(self, recursive=1, base=0, **kw):
"""
Returns a list of tuples by parsing recursively all categories in a
given list of base categories. Uses getLogicalPath as default method
"""
return self.getCategoryChildItemList(recursive=recursive, display_id='compact_logical_path', base=base, **kw)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildIndentedTitleItemList') 'getCategoryChildIndentedTitleItemList')
def getCategoryChildIndentedTitleItemList(self, recursive=1, base=0, **kw): def getCategoryChildIndentedTitleItemList(self, recursive=1, base=0, **kw):
...@@ -342,7 +371,8 @@ class Category(Folder): ...@@ -342,7 +371,8 @@ class Category(Folder):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildItemList') 'getCategoryChildItemList')
def getCategoryChildItemList(self, recursive=1, base=0, **kw): def getCategoryChildItemList(self, recursive=1, base=0,
cache=DEFAULT_CACHE_FACTORY, **kw):
""" """
Returns a list of tuples by parsing recursively all categories in a Returns a list of tuples by parsing recursively all categories in a
given list of base categories. Each tuple contains:: given list of base categories. Each tuple contains::
...@@ -360,9 +390,21 @@ class Category(Folder): ...@@ -360,9 +390,21 @@ class Category(Folder):
recursive -- if set to 0 do not apply recursively recursive -- if set to 0 do not apply recursively
""" """
def _renderCategoryChildItemList(recursive=1, base=0, **kw):
value_list = self.getCategoryChildValueList(recursive=recursive,**kw) value_list = self.getCategoryChildValueList(recursive=recursive,**kw)
return Renderer(base=base, **kw).render(value_list) return Renderer(base=base, **kw).render(value_list)
if not cache:
return _renderCategoryChildItemList(recursive=recursive, base=base, **kw)
# Some methods are language dependent so we include the language in the key
localizer = getToolByName(self, 'Localizer')
language = localizer.get_selected_language()
m = CachingMethod(_renderCategoryChildItemList,
('Category_getCategoryChildItemList', language, self.getPath()))
return m(recursive=recursive, base=base, **kw)
# Alias for compatibility # Alias for compatibility
security.declareProtected(Permissions.View, 'getFormItemList') security.declareProtected(Permissions.View, 'getFormItemList')
def getFormItemList(self): def getFormItemList(self):
......
...@@ -1346,6 +1346,18 @@ class Base( CopyContainer, ...@@ -1346,6 +1346,18 @@ class Base( CopyContainer,
objectlist.append(objectlist[-1][element]) objectlist.append(objectlist[-1][element])
return '/' + join([object.getTitle() for object in objectlist[1:]], '/') return '/' + join([object.getTitle() for object in objectlist[1:]], '/')
security.declareProtected(Permissions.AccessContentsInformation, 'getCompactLogicalPath')
def getCompactLogicalPath(self, REQUEST=None) :
"""
Returns a compact representation of the absolute path of an object
using compact titles when available
"""
pathlist = self.getPhysicalPath()
objectlist = [self.getPhysicalRoot()]
for element in pathlist[1:] :
objectlist.append(objectlist[-1][element])
return '/' + join([object.getCompactTitle() for object in objectlist[1:]], '/')
security.declareProtected(Permissions.AccessContentsInformation, 'getUrl') security.declareProtected(Permissions.AccessContentsInformation, 'getUrl')
def getUrl(self, REQUEST=None): def getUrl(self, REQUEST=None):
""" """
...@@ -1871,9 +1883,9 @@ class Base( CopyContainer, ...@@ -1871,9 +1883,9 @@ class Base( CopyContainer,
'getTranslatedShortTitleOrId') 'getTranslatedShortTitleOrId')
def getTranslatedShortTitleOrId(self): def getTranslatedShortTitleOrId(self):
""" """
Returns the translated title or the id if the id is empty Returns the translated short title or the id if the id is empty
""" """
title = self.getTranslatedTitle() title = self.getTranslatedShortTitle()
if title is not None: if title is not None:
title = str(title) title = str(title)
if title == '' or title is None: if title == '' or title is None:
...@@ -1897,6 +1909,24 @@ class Base( CopyContainer, ...@@ -1897,6 +1909,24 @@ class Base( CopyContainer,
return title return title
return self.getId() return self.getId()
security.declareProtected(Permissions.AccessContentsInformation,
'getCompactTitle')
def getCompactTitle(self):
"""
Returns the translated short title or the reference or
the translated title or the ID by order of priority
NOTE: It could be useful to make this method overridable
with a type methode.
"""
if self.hasShortTitle():
return self.getTranslatedShortTitle()
if self.hasReference():
return self.getReference()
if self.hasTitle():
return self.getTranslatedTitle()
return self.getId()
# This method allows to sort objects in list is a more reasonable way # This method allows to sort objects in list is a more reasonable way
security.declareProtected(Permissions.View, 'getIntId') security.declareProtected(Permissions.View, 'getIntId')
def getIntId(self): def getIntId(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