From 411cb7f8046688281bc665e6881e21252e78d819 Mon Sep 17 00:00:00 2001
From: Jean-Paul Smets <jp@nexedi.com>
Date: Sun, 15 Jul 2007 11:28:52 +0000
Subject: [PATCH] getDomainByPath can now accept a default parameter so that a
 defaultvalue is returned in case of exception. This is used for example in
 Listbox.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15217 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Tool/DomainTool.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/product/ERP5/Tool/DomainTool.py b/product/ERP5/Tool/DomainTool.py
index 0952b15adf..10c388a122 100644
--- a/product/ERP5/Tool/DomainTool.py
+++ b/product/ERP5/Tool/DomainTool.py
@@ -35,6 +35,8 @@ from Products.ERP5Type.Tool.BaseTool import BaseTool
 from zLOG import LOG
 from DateTime import DateTime
 
+_MARKER = []
+
 class DomainTool(BaseTool):
     """
         A tool to define reusable ranges and subranges through
@@ -291,13 +293,18 @@ class DomainTool(BaseTool):
       object_list.extend(parent.getDomainGeneratorList(**kw))
       return object_list
 
-    def getDomainByPath(self, path):
+
+    def getDomainByPath(self, path, default=_MARKER):
       """
       Return the domain object for a given path
       """
       path = path.split('/')
       base_domain_id = path[0]
-      domain = self[base_domain_id]
+      if default is _MARKER:
+        domain = self[base_domain_id]
+      else:
+        domain = self.get(base_domain_id, _MARKER)
+        if domain is _MARKER: return default
       for depth, subdomain in enumerate(path[1:]):
         domain_list = self.getChildDomainValueList(domain, depth=depth)
         for d in domain_list:
@@ -305,6 +312,7 @@ class DomainTool(BaseTool):
             domain = d
             break
         else:
+          if domain is _MARKER: return default
           raise KeyError, subdomain
       return domain
   
-- 
2.30.9