[Erp5-report] r37288 jerome - /erp5/trunk/products/ERP5Form/MatrixBox.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Jul 27 16:28:15 CEST 2010


Author: jerome
Date: Tue Jul 27 16:28:12 2010
New Revision: 37288

URL: http://svn.erp5.org?rev=37288&view=rev
Log:
small optimizations:
 - use 'key in dict' rather than has_key
 - create invariant "base_id" dict outside of the loop

Modified:
    erp5/trunk/products/ERP5Form/MatrixBox.py

Modified: erp5/trunk/products/ERP5Form/MatrixBox.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/MatrixBox.py?rev=37288&r1=37287&r2=37288&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Form/MatrixBox.py [utf8] (original)
+++ erp5/trunk/products/ERP5Form/MatrixBox.py [utf8] Tue Jul 27 16:28:12 2010
@@ -287,6 +287,7 @@ class MatrixBoxWidget(Widget.Widget):
             extra_dimension_index = '_'+'_'.join(map(str, extra_dimension_position))
           # Create one table per tab
           k = 0
+          kwd = dict(base_id=cell_base_id)
           for tab in tabs:
             tab_id = tab[0]
             if (tab_id is not None) and \
@@ -358,8 +359,6 @@ class MatrixBoxWidget(Widget.Widget):
                   kw = [l[0], c[0]]
                 else:
                   kw = [l[0], c[0]] + tab_id + extra_dimension_category_list
-                kwd = {}
-                kwd['base_id'] = cell_base_id
                 cell = cell_getter_method(*kw, **kwd)
                 REQUEST['cell'] = cell
                 REQUEST['cell_index'] = kw
@@ -415,7 +414,7 @@ class MatrixBoxWidget(Widget.Widget):
                              cell_position=((i,j,k)+extra_dimension_position)):
                             cell_html = "<a href='%s'>%s</a>" % (cell_url,
                                                                  cell_html)
-                        if field_errors.has_key(key):
+                        if key in field_errors:
                           # Display error message if this cell has an error
                           has_error = True
                           cell_body += '<span class="input">%s</span>%s' % (
@@ -440,7 +439,7 @@ class MatrixBoxWidget(Widget.Widget):
                                                     attribute_value)
                         else:
                           display_value = attribute_value
-                        if field_errors.has_key(key):
+                        if key in field_errors:
                           # Display error message if this cell has an error
                           has_error = True
                           cell_body += '<span class="input">%s</span>%s' % (
@@ -566,6 +565,7 @@ class MatrixBoxValidator(Validator.Valid
             extra_dimension_index = '_'+'_'.join(map(str, extra_dimension_position))
           k = 0
           # Create one table per tab
+          kwd = dict(base_id=cell_base_id)
           for tab_id in tab_ids:
             if (tab_id is not None) and \
                (not isinstance(tab_id, (list, tuple))):
@@ -583,8 +583,6 @@ class MatrixBoxValidator(Validator.Valid
                 else:
                   kw = [l, c] + tab_id + extra_dimension_category_list
                 kw = tuple(kw)
-                kwd = {}
-                kwd['base_id'] = cell_base_id
                 cell = cell_getter_method(*kw, **kwd)
                 
                 for attribute_id in editable_attribute_ids:
@@ -609,9 +607,8 @@ class MatrixBoxValidator(Validator.Valid
                           and not my_field.get_value('hidden'):
                         # Only validate modified values from visible fields
                         result.setdefault(kw, {})[attribute_id] = value
-                      else:
-                        if result.has_key(kw):
-                          result[kw][attribute_id] = value
+                      elif kw in result:
+                        result[kw][attribute_id] = value
                 j += 1
               i += 1
             k += 1




More information about the Erp5-report mailing list