[Checkins] SVN: z3ext.layoutform/trunk/ Add a patched version of sequence converters from z3c.form's trunk.

Dan Korostelev nadako at gmail.com
Sun Feb 22 04:35:24 EST 2009


Log message for revision 97010:
  Add a patched version of sequence converters from z3c.form's trunk.

Changed:
  U   z3ext.layoutform/trunk/CHANGES.txt
  A   z3ext.layoutform/trunk/src/z3ext/layoutform/converter.py
  A   z3ext.layoutform/trunk/src/z3ext/layoutform/converter.zcml

-=-
Modified: z3ext.layoutform/trunk/CHANGES.txt
===================================================================
--- z3ext.layoutform/trunk/CHANGES.txt	2009-02-22 09:06:47 UTC (rev 97009)
+++ z3ext.layoutform/trunk/CHANGES.txt	2009-02-22 09:35:24 UTC (rev 97010)
@@ -2,7 +2,15 @@
 CHANGES
 =======
 
+1.3.3 (unreleased)
+------------------
 
+- Added a patched sequence converters that don't raise a LookupError
+  when dealing with values that are removed from the terms. This
+  is fixed in z3c.form's 2.0.0, so it's only needed when using z3c.form
+  1.9.x and below. Include the ``converter.zcml`` file with the
+  ``includeOverrides`` directive, if you need it.
+
 - Added applyChanges method to subform
 
 

Added: z3ext.layoutform/trunk/src/z3ext/layoutform/converter.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/converter.py	                        (rev 0)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/converter.py	2009-02-22 09:35:24 UTC (rev 97010)
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Patched form converters for z3c.form 1.9
+
+This module contains patched versions of z3c.form sequence converters
+that fix an exception raised when the passed value is no more in terms.
+
+This is already fixed in current z3c.form trunk (2.0+), so if you use
+2.0, you don't need these converters.
+
+$Id$
+"""
+from z3c.form import converter
+
+
+class SequenceDataConverter(converter.SequenceDataConverter):
+
+    def toWidgetValue(self, value):
+        if value is self.field.missing_value:
+            return []
+        terms = self.widget.updateTerms()
+        try:
+            return [terms.getTerm(value).token]
+        except LookupError, err:
+            return []
+
+
+class CollectionSequenceDataConverter(converter.CollectionSequenceDataConverter):
+
+    def toWidgetValue(self, value):
+        if value is self.field.missing_value:
+            return []
+        terms = self.widget.updateTerms()
+        values = []
+        for entry in value:
+            try:
+                values.append(terms.getTerm(entry).token)
+            except LookupError, err:
+                pass
+        return values


Property changes on: z3ext.layoutform/trunk/src/z3ext/layoutform/converter.py
___________________________________________________________________
Added: svn:keywords
   + Id

Added: z3ext.layoutform/trunk/src/z3ext/layoutform/converter.zcml
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/converter.zcml	                        (rev 0)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/converter.zcml	2009-02-22 09:35:24 UTC (rev 97010)
@@ -0,0 +1,11 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+  <!--
+  Note, that you definitely don't need this file if you are using
+  z3c.form 2.0+ or the current (2009-02-22) z3c.form trunk.
+  -->
+
+  <adapter factory=".converter.SequenceDataConverter" />
+  <adapter factory=".converter.CollectionSequenceDataConverter" />
+
+</configure>



More information about the Checkins mailing list