Author: pjenvey
Date: 2008-12-19 17:25:19 -0700 (Fri, 19 Dec 2008)
New Revision: 3742
Modified:
FormEncode/trunk/formencode/national.py
Log:
o fix the Invalid zip code message
o only warn about lack of pycountry/tg in Country/LanguageValidator
fixes #2347094, #2347378
pointed out by Brendan Doms
Modified: FormEncode/trunk/formencode/national.py
===================================================================
--- FormEncode/trunk/formencode/national.py 2008-12-20 00:22:15 UTC (rev
3741)
+++ FormEncode/trunk/formencode/national.py 2008-12-20 00:25:19 UTC (rev
3742)
@@ -14,6 +14,12 @@
except:
has_turbogears = False
+no_country = False
+if not (has_pycountry or has_turbogears):
+ import warnings
+ no_country = ('Please easy_install pycountry or validators handling '
+ 'country names and/or languages will not work.')
+
############################################################
## country lists and functions
############################################################
@@ -83,10 +89,6 @@
def get_language(code):
return _l(pycountry.languages.get(alpha2=code).name)
-else:
- from warnings import warn
- warn('Please easy_install pycountry or validators handling country names
and/or languages will not work.', DeprecationWarning)
-#endif
############################################################
## country, state and postal code validators
@@ -153,7 +155,7 @@
Regex.__init__(self, *args, **kw)
messages = {
- 'invalid': _('Please enter a zip code (%s)'),
+ 'invalid': _('Please enter a zip code (%%s)'),
}
def _to_python(self, value, state):
@@ -327,6 +329,11 @@
'valueNotFound': _("That country is not listed in ISO 3166"),
}
+ def __init__(self, *args, **kw):
+ FancyValidator.__init__(self, *args, **kw)
+ if no_country:
+ warnings.warn(no_country, Warning, 2)
+
def _to_python(self, value, state):
upval = value.upper()
if self.key_ok:
@@ -706,6 +713,11 @@
'valueNotFound': _("That language is not listed in ISO 639"),
}
+ def __init__(self, *args, **kw):
+ FancyValidator.__init__(self, *args, **kw)
+ if no_country:
+ warnings.warn(no_country, Warning, 2)
+
def _to_python(self, value, state):
upval = value.upper()
if self.key_ok:
------------------------------------------------------------------------------
_______________________________________________
FormEncode-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs