[Checkins] SVN: z3c.form/trunk/ Fix python 2.6 warnings/failures.

Dan Korostelev nadako at gmail.com
Sat Feb 28 07:26:20 EST 2009


Log message for revision 97381:
  Fix python 2.6 warnings/failures.
  
  Move formErrorsMessage to the base Form class as it's quite useful in every validating form.
  
  Don't import ViewPageTemplateFile name from z3c.ptcompat to local namespace, use module attribute access instead, because ptcompat can be reloaded and the ViewPageTemplateFile object can change because of that.

Changed:
  U   z3c.form/trunk/CHANGES.txt
  U   z3c.form/trunk/buildout.cfg
  U   z3c.form/trunk/src/z3c/form/converter.py
  U   z3c.form/trunk/src/z3c/form/error.py
  U   z3c.form/trunk/src/z3c/form/form.py
  U   z3c.form/trunk/src/z3c/form/tests/test_doc.py
  U   z3c.form/trunk/src/z3c/form/zcml.txt

-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt	2009-02-28 11:46:44 UTC (rev 97380)
+++ z3c.form/trunk/CHANGES.txt	2009-02-28 12:26:20 UTC (rev 97381)
@@ -138,6 +138,13 @@
   querying for an adapter for (field, field.vocabulary, request) so it can be
   differentiated according to the type of the source used for the field.
 
+- Feature: move ``formErrorsMessage`` attribute from AddForm and EditForm
+  to the ``z3c.form.form.Form`` base class as it's very common validation
+  status message and can be easily reused (especially when translations
+  are provided).
+
+- Fix: Don't cause warnings in Python 2.6.
+
 Version 1.9.0 (2008-08-26)
 --------------------------
 

Modified: z3c.form/trunk/buildout.cfg
===================================================================
--- z3c.form/trunk/buildout.cfg	2009-02-28 11:46:44 UTC (rev 97380)
+++ z3c.form/trunk/buildout.cfg	2009-02-28 12:26:20 UTC (rev 97381)
@@ -1,6 +1,6 @@
 [buildout]
 develop = . benchmark
-parts = test checker coverage-test coverage-report docs i18n benchmark
+parts = test checker coverage-test coverage-report docs i18n benchmark python
 
 [test-environment]
 CHAMELEON_DEBUG = False
@@ -64,3 +64,8 @@
 [benchmark-environment]
 CHAMELEON_DEBUG = False
 CHAMELEON_CACHE = True
+
+[python]
+recipe = zc.recipe.egg
+eggs = z3c.form
+interpreter = python

Modified: z3c.form/trunk/src/z3c/form/converter.py
===================================================================
--- z3c.form/trunk/src/z3c/form/converter.py	2009-02-28 11:46:44 UTC (rev 97380)
+++ z3c.form/trunk/src/z3c/form/converter.py	2009-02-28 12:26:20 UTC (rev 97381)
@@ -81,6 +81,8 @@
 
 class FormatterValidationError(zope.schema.ValidationError):
 
+    message = None # redefine here, so Python 2.6 won't raise warning
+
     def __init__(self, message, value):
         zope.schema.ValidationError.__init__(self, message, value)
         self.message = message

Modified: z3c.form/trunk/src/z3c/form/error.py
===================================================================
--- z3c.form/trunk/src/z3c/form/error.py	2009-02-28 11:46:44 UTC (rev 97380)
+++ z3c.form/trunk/src/z3c/form/error.py	2009-02-28 12:26:20 UTC (rev 97381)
@@ -20,7 +20,7 @@
 import zope.component
 import zope.interface
 import zope.schema
-from z3c.ptcompat import ViewPageTemplateFile
+from z3c import ptcompat
 from zope.pagetemplate.interfaces import IPageTemplate
 
 import z3c.form
@@ -127,7 +127,7 @@
     template = None
 
     def __init__(self, filename, contentType='text/html'):
-        self.template = ViewPageTemplateFile(filename, content_type=contentType)
+        self.template = ptcompat.ViewPageTemplateFile(filename, content_type=contentType)
 
     def __call__(self, errorView, request):
         return self.template

Modified: z3c.form/trunk/src/z3c/form/form.py
===================================================================
--- z3c.form/trunk/src/z3c/form/form.py	2009-02-28 11:46:44 UTC (rev 97380)
+++ z3c.form/trunk/src/z3c/form/form.py	2009-02-28 12:26:20 UTC (rev 97381)
@@ -21,7 +21,7 @@
 import zope.component
 import zope.event
 import zope.lifecycleevent
-from z3c.ptcompat import ViewPageTemplateFile
+from z3c import ptcompat
 from zope.publisher import browser
 from zope.pagetemplate.interfaces import IPageTemplate
 from zope.schema.fieldproperty import FieldProperty
@@ -180,6 +180,9 @@
     actions = FieldProperty(interfaces.IActionForm['actions'])
     refreshActions = FieldProperty(interfaces.IActionForm['refreshActions'])
 
+    # common string for use in validation status messages
+    formErrorsMessage = _('There were some errors.')
+
     @property
     def action(self):
         """See interfaces.IInputForm"""
@@ -217,7 +220,6 @@
     ignoreReadonly = True
 
     _finishedAdd = False
-    formErrorsMessage = _('There were some errors.')
 
     @button.buttonAndHandler(_('Add'), name='add')
     def handleAdd(self, action):
@@ -256,7 +258,6 @@
     """A simple edit form with an apply button."""
     zope.interface.implements(interfaces.IEditForm)
 
-    formErrorsMessage = _('There were some errors.')
     successMessage = _('Data successfully updated.')
     noChangesMessage = _('No changes were applied.')
 
@@ -293,7 +294,7 @@
 
     def __init__(self, filename, contentType='text/html', form=None,
         request=None):
-        self.template = ViewPageTemplateFile(filename, content_type=contentType)
+        self.template = ptcompat.ViewPageTemplateFile(filename, content_type=contentType)
         zope.component.adapter(
             util.getSpecification(form),
             util.getSpecification(request))(self)

Modified: z3c.form/trunk/src/z3c/form/tests/test_doc.py
===================================================================
--- z3c.form/trunk/src/z3c/form/tests/test_doc.py	2009-02-28 11:46:44 UTC (rev 97380)
+++ z3c.form/trunk/src/z3c/form/tests/test_doc.py	2009-02-28 12:26:20 UTC (rev 97381)
@@ -103,6 +103,9 @@
                  (re.compile(
                   r"(invalid literal for int\(\)) with base 10: '(.*)'"),
                   r'\1: \2'),
+                 (re.compile(
+                  r"Decimal\('(.*)'\)"),
+                  r'Decimal("\1")'),
                  ])
             ),
         doctest.DocFileSuite(

Modified: z3c.form/trunk/src/z3c/form/zcml.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/zcml.txt	2009-02-28 11:46:44 UTC (rev 97380)
+++ z3c.form/trunk/src/z3c/form/zcml.txt	2009-02-28 12:26:20 UTC (rev 97381)
@@ -74,8 +74,8 @@
 
 and check it:
 
-  >>> from z3c.ptcompat import ViewPageTemplateFile
-  >>> isinstance(template, ViewPageTemplateFile)
+  >>> from z3c import ptcompat
+  >>> isinstance(template, ptcompat.ViewPageTemplateFile)
   True
 
 Let's use the template within the widget.
@@ -178,7 +178,7 @@
 
 and check it:
 
-  >>> isinstance(template, ViewPageTemplateFile)
+  >>> isinstance(template, ptcompat.ViewPageTemplateFile)
   True
 
 Let's use the template within the widget.



More information about the Checkins mailing list