From 5d149e641eca67d32ec8c285b23547fcbf84d7c4 Mon Sep 17 00:00:00 2001 From: Alexandre Boeglin <alex@nexedi.com> Date: Sat, 5 Nov 2005 16:26:05 +0000 Subject: [PATCH] Added getCategoryChildIndentedTitleItemList and getIndentedTitle. It allows to display hierarchical data in much less horizontal space than getCategoryChildLogicalPathItemList. example : getCategoryChildLogicalPathItemList : Foooooooo Foooooooo/Baaaaaaaar Foooooooo/Baaaaaaaar/Baaaaaaaaz Foooooooo/Baaaaaaaar/Baaaaaaaaz/Quuuuuuuux getCategoryChildIndentedTitleItemList : Foooooooo Baaaaaaaar Baaaaaaaaz Quuuuuuuux Possible improvements : for now, I just add some " " before the title, but it breaks the mozilla "type and search" feature. Maybe it is possible to use CSS to get the same visual result ... git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4253 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/CMFCategory/Category.py | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/product/CMFCategory/Category.py b/product/CMFCategory/Category.py index f36105e509..445f043a86 100755 --- a/product/CMFCategory/Category.py +++ b/product/CMFCategory/Category.py @@ -170,6 +170,31 @@ class Category(Folder): logical_title_list.append(logical_title) return '/'.join(logical_title_list) + security.declareProtected(Permissions.AccessContentsInformation, + 'getIndentedTitle') + def getIndentedTitle(self): + """ + Returns title or id, indented from base_category. + """ + path_len = 0 + base = self.getBaseCategory() + current = self + while not current is base : + path_len += 1 + current = aq_parent(current) + + # it s better for the user to display something than only ''... + logical_title_list = [] + + if path_len >= 2: + logical_title_list.append(' ' * 4 * (path_len - 1)) + + logical_title = self.getTitle() + if logical_title in [None, '']: + logical_title = object.getId() + logical_title_list.append(logical_title) + return ''.join(logical_title_list) + security.declareProtected(Permissions.AccessContentsInformation, 'getCategoryChildValueList') def getCategoryChildValueList(self, recursive=1, include_if_child=1, sort_on=None, sort_order=None, **kw): @@ -253,6 +278,16 @@ class Category(Folder): """ return self.getCategoryChildItemList(recursive = recursive, display_id='logical_path', base=base, **kw) + security.declareProtected(Permissions.AccessContentsInformation, + 'getCategoryChildIndentedTitleItemList') + def getCategoryChildIndentedTitleItemList(self, recursive=1, base=0, **kw): + """ + Returns a list of tuples by parsing recursively all categories in a + given list of base categories. Uses getIndentedTitle as default method + """ + return self.getCategoryChildItemList(recursive = recursive, + display_id='indented_title', base=base, **kw) + security.declareProtected(Permissions.AccessContentsInformation, 'getCategoryChildIdItemList') def getCategoryChildIdItemList(self, recursive=1, base=0, **kw): -- 2.30.9