From 040c8361484d1ca106ffb9f6876e52453fbe69e5 Mon Sep 17 00:00:00 2001
From: Nicolas Delaby <nicolas@nexedi.com>
Date: Thu, 20 Dec 2007 10:44:49 +0000
Subject: [PATCH] Add new displaying Method indented_title_and_id

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18447 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/CMFCategory/Category.py | 36 ++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/product/CMFCategory/Category.py b/product/CMFCategory/Category.py
index cd542be595..c287590c29 100644
--- a/product/CMFCategory/Category.py
+++ b/product/CMFCategory/Category.py
@@ -211,6 +211,30 @@ class Category(Folder):
       logical_title_list.append(logical_title)
       return ''.join(logical_title_list)
 
+    security.declareProtected(Permissions.AccessContentsInformation,
+                                                    'getIndentedTitleAndId')
+    def getIndentedTitleAndId(self, item_method='getTitleAndId'):
+      """
+        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('&nbsp;' * 4 * (path_len - 1))
+      logical_title = getattr(self, item_method)()
+      if logical_title in [None, '']:
+        logical_title = self.getId()
+      logical_title_list.append(logical_title)
+      return ''.join(logical_title_list)
+
     security.declareProtected(Permissions.AccessContentsInformation,
                                                     'getTranslatedIndentedTitle')
     def getTranslatedIndentedTitle(self):
@@ -430,6 +454,17 @@ class Category(Folder):
       return self.getCategoryChildItemList(recursive=recursive,
           display_id='indented_title', base=base, **kw)
 
+    security.declareProtected(Permissions.AccessContentsInformation,
+                                     'getCategoryChildIndentedTitleAndIdItemList')
+    def getCategoryChildIndentedTitleAndIdItemList(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_and_id', base=base, **kw)
+
     security.declareProtected(Permissions.AccessContentsInformation,
                                      'getCategoryChildTranslatedIndentedTitleItemList')
     def getCategoryChildTranslatedIndentedTitleItemList(self,
@@ -832,4 +867,3 @@ class BaseCategory(Category):
 
 InitializeClass( Category )
 InitializeClass( BaseCategory )
-
-- 
2.30.9