[Erp5-report] r19912 - in /experimental/Experimental: ./ patches/
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Mar 14 15:52:59 CET 2008
Author: bartek
Date: Fri Mar 14 15:52:58 2008
New Revision: 19912
URL: http://svn.erp5.org?rev=19912&view=rev
Log:
ParallelListField validator rewritten so that we can use JS-based field
Added:
experimental/Experimental/patches/ERP5Form_DynamicParallelListField.py
Modified:
experimental/Experimental/ZopePatch.py
Modified: experimental/Experimental/ZopePatch.py
URL: http://svn.erp5.org/experimental/Experimental/ZopePatch.py?rev=19912&r1=19911&r2=19912&view=diff
==============================================================================
--- experimental/Experimental/ZopePatch.py (original)
+++ experimental/Experimental/ZopePatch.py Fri Mar 14 15:52:58 2008
@@ -46,3 +46,6 @@
LOG('EXPERIMENTAL monkey-patch', INFO, 'Allow marking listbox lines with a custom css')
from Products.Experimental.patches import ERP5Form_ListBox_line_marking
+
+LOG('EXPERIMENTAL monkey-patch', INFO, 'Let ParallelListField work with JS-driven frontend')
+from Products.Experimental.patches import ERP5Form_DynamicParallelListField
Added: experimental/Experimental/patches/ERP5Form_DynamicParallelListField.py
URL: http://svn.erp5.org/experimental/Experimental/patches/ERP5Form_DynamicParallelListField.py?rev=19912&view=auto
==============================================================================
--- experimental/Experimental/patches/ERP5Form_DynamicParallelListField.py (added)
+++ experimental/Experimental/patches/ERP5Form_DynamicParallelListField.py Fri Mar 14 15:52:58 2008
@@ -1,0 +1,77 @@
+##############################################################################
+#
+# Copyright (c) 2007 ERP5 Polska. All Rights Reserved.
+# Bartek Gorny <bartek at erp5.pl>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+"""
+ This patch allows a use of JS-driven ParallelListField.
+ JavaScript to drive the field is in the erp5_xhtml_style_experimental bt5.
+ The patch is needed because stock validator uses hash script and validates
+ only as much fields as the hash script returned (which means length of the old
+ list plus 1), and breaks when the boxes where cleared.
+
+ RATIONALE: speed up user's work, reduce server load.
+"""
+
+from Products.ERP5Form.ParallelListField import ParallelListValidator, generateSubForm
+from Products.Formulator.Errors import ValidationError
+from zLOG import LOG
+
+
+def ParallelListField_validate(self, field, key, REQUEST):
+ # we use hash script only to get standard set of properties
+ # then look in the REQUEST how many subfields were sent
+ result_list = []
+ hash_list = generateSubForm(field, field.get_value('default'), REQUEST)
+ property_dict = hash_list[0]
+ is_sub_field_required = 0
+ i = 0
+ while 1:
+ item_key = field.generate_subfield_key(i, validation=1, key=key)
+ item_value = REQUEST.get(item_key, None)
+ if item_value is None:
+ break
+ property_dict['key'] = i
+ try:
+ sub_result_list = self.validate_sub_field(field, item_key, REQUEST, property_dict)
+ if not isinstance(sub_result_list, (list, tuple)):
+ sub_result_list = [sub_result_list]
+ else:
+ sub_result_list = list(sub_result_list)
+ result_list.extend(sub_result_list)
+ except ValidationError:
+ is_sub_field_required = 1
+ i += 1
+ if result_list == []:
+ if field.get_value('required'):
+ self.raise_error('required_not_found', field)
+ else:
+ if is_sub_field_required:
+ self.raise_error('required_not_found', field)
+ return result_list
+
+
+ParallelListValidator.validate = ParallelListField_validate
+
More information about the Erp5-report
mailing list