From 5b8325ed4e15e4b05521f0be523cea709028ccd6 Mon Sep 17 00:00:00 2001
From: Kevin Deldycke <kevin@nexedi.com>
Date: Fri, 28 Jul 2006 16:30:59 +0000
Subject: [PATCH] Add getListMethodName on Listboxes. Fix code indention.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8879 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/ListBox.py | 38 +++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/product/ERP5Form/ListBox.py b/product/ERP5Form/ListBox.py
index 6217d078f7..3007b07b24 100644
--- a/product/ERP5Form/ListBox.py
+++ b/product/ERP5Form/ListBox.py
@@ -2878,25 +2878,35 @@ class ListBoxValidator(Validator.Validator):
 ListBoxValidatorInstance = ListBoxValidator()
 
 class ListBox(ZMIField):
-    meta_type = "ListBox"
+  meta_type = "ListBox"
 
-    widget = ListBoxWidgetInstance
-    validator = ListBoxValidatorInstance
+  widget = ListBoxWidgetInstance
+  validator = ListBoxValidatorInstance
 
-    security = ClassSecurityInfo()
+  security = ClassSecurityInfo()
 
-    security.declareProtected('Access contents information', 'get_value')
-    def get_value(self, id, **kw):
-      if (id == 'default'):
-        if (kw.get('render_format') in ('list', )):
-          return self.widget.render(self, self.generate_field_key(), None,
-                                    kw.get('REQUEST'),
-                                    render_format=kw.get('render_format'))
-        else:
-          return None
+  security.declareProtected('Access contents information', 'get_value')
+  def get_value(self, id, **kw):
+    if (id == 'default'):
+      if (kw.get('render_format') in ('list', )):
+        return self.widget.render(self, self.generate_field_key(), None,
+                                  kw.get('REQUEST'),
+                                  render_format=kw.get('render_format'))
       else:
-        return ZMIField.get_value(self, id, **kw)
+        return None
+    else:
+      return ZMIField.get_value(self, id, **kw)
 
+  security.declareProtected('Access contents information', 'getListMethodName')
+  def getListMethodName(self):
+    """Return the name of the list method. If not defined, return None.
+    """
+    list_method = self.get_value('list_method')
+    try:
+      name = getattr(list_method, 'method_name')
+    except AttributeError:
+      name = list_method
+    return name or None
 
 
 class ListBoxLine:
-- 
2.30.9