From 77a53809e6015f41ca84e1154c0ffa5a74958364 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 28 May 2013 11:22:50 +0200
Subject: [PATCH] fix undefined variables

---
 product/ERP5Form/ListBox.py | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/product/ERP5Form/ListBox.py b/product/ERP5Form/ListBox.py
index 73110dcbec..68f72bf50f 100644
--- a/product/ERP5Form/ListBox.py
+++ b/product/ERP5Form/ListBox.py
@@ -2781,12 +2781,10 @@ class ListBoxValidator(Validator.Validator):
         for uid in listbox_uids:
           if uid[:4] == 'new_':
             if object_dict is None:
+              object_dict = {}
               list_method = field.get_value('list_method')
               list_method = getattr(here, list_method.method_name)
-              #LOG('ListBoxValidator', 0, 'call %s' % repr(list_method))
-              object_list = list_method(REQUEST=REQUEST, **params)
-              object_dict = dict()
-              for obj in object_list:
+              for obj in list_method(REQUEST=REQUEST, **params):
                 o_uid = obj.getUid()
                 assert o_uid not in object_dict,\
                   "List method returned duplicate uid %s %s" % (
@@ -2822,20 +2820,17 @@ class ListBoxValidator(Validator.Validator):
 
         # Here we generate again the object_list with listbox the listbox we
         # have just created
-        # XXX why ? -jerome
         if listbox:
+          object_dict = {}
           list_method = field.get_value('list_method')
           list_method = getattr(here, list_method.method_name)
           REQUEST.set(field.id, listbox)
-          object_list = list_method(REQUEST=REQUEST, **params)
-          object_dict = dict()
-          for obj in object_list:
+          for obj in list_method(REQUEST=REQUEST, **params):
             o_uid = obj.getUid()
             assert o_uid not in object_dict,\
               "List method returned duplicate uid %s" % o_uid
             object_dict[o_uid] = obj
 
-
         for uid in listbox_uids:
           row_result = {}
           if uid[:4] == 'new_':
@@ -2878,19 +2873,20 @@ class ListBoxValidator(Validator.Validator):
               except (KeyError, NotFound, ValueError), err:
                 # It is possible that this object is not catalogged yet. So
                 # the object must be obtained from ZODB.
-                if object_list is None:
+                if object_dict is None:
+                  object_dict = {}
                   list_method = field.get_value('list_method')
                   list_method = getattr(here, list_method.method_name)
-                  object_list = list_method(REQUEST=REQUEST, **params)
-                for o in object_list:
-                  try:
-                    if o.getUid() == int(uid):
-                      break
-                  except ValueError:
-                    if str(o.getUid()) == uid:
-                      break
-                else:
-                  raise err
+                  for obj in list_method(REQUEST=REQUEST, **params):
+                    o_uid = str(obj.getUid())
+                    assert o_uid not in object_dict,\
+                      "List method returned duplicate uid %s" % o_uid
+                    object_dict[o_uid] = obj
+
+                  o = object_dict.get(str(uid))
+                  if o is None:
+                    raise err
+
               row_key = o.getUrl()
               for sql in editable_column_ids:
                 editable_field = editable_field_dict.get(sql.replace('.', '_'))
-- 
2.30.9