Author: Honza_Kral
Date: 2009-06-02 21:36:16 -0500 (Tue, 02 Jun 2009)
New Revision: 10899

Modified:
   django/branches/soc2009/model-validation/django/forms/fields.py
Log:
[soc2009/model-validation] added validators param to FormField

This is still not used anywhere

Modified: django/branches/soc2009/model-validation/django/forms/fields.py
===================================================================
--- django/branches/soc2009/model-validation/django/forms/fields.py     
2009-06-03 02:35:59 UTC (rev 10898)
+++ django/branches/soc2009/model-validation/django/forms/fields.py     
2009-06-03 02:36:16 UTC (rev 10899)
@@ -24,6 +24,7 @@
     from sets import Set as set
 
 from django.core.exceptions import ValidationError
+from django.core import validators
 from django.utils.translation import ugettext_lazy as _
 from django.utils.encoding import smart_unicode, smart_str
 
@@ -52,6 +53,7 @@
 class Field(object):
     widget = TextInput # Default widget to use when rendering this type of 
Field.
     hidden_widget = HiddenInput # Default widget to use when rendering this as 
"hidden".
+    default_validators = [] # Default set of validators
     default_error_messages = {
         'required': _(u'This field is required.'),
         'invalid': _(u'Enter a valid value.'),
@@ -61,7 +63,8 @@
     creation_counter = 0
 
     def __init__(self, required=True, widget=None, label=None, initial=None,
-                 help_text=None, error_messages=None, 
show_hidden_initial=False):
+                 help_text=None, error_messages=None, 
show_hidden_initial=False,
+                 validators=[]):
         # required -- Boolean that specifies whether the field is required.
         #             True by default.
         # widget -- A Widget class, or instance of a Widget class, that should
@@ -77,6 +80,7 @@
         # help_text -- An optional string to use as "help text" for this Field.
         # show_hidden_initial -- Boolean that specifies if it is needed to 
render a
         #                        hidden widget with initial value after widget.
+        # validators -- List of addtional validators to use
         if label is not None:
             label = smart_unicode(label)
         self.required, self.label, self.initial = required, label, initial
@@ -109,6 +113,7 @@
         set_class_error_messages(messages, self.__class__)
         messages.update(error_messages or {})
         self.error_messages = messages
+        self.validators = self.default_validators + validators
 
     def clean(self, value):
         """
@@ -164,6 +169,7 @@
             return {'maxlength': str(self.max_length)}
 
 class IntegerField(Field):
+    default_validators = [validators.validate_integer]
     default_error_messages = {
         'invalid': _(u'Enter a whole number.'),
         'max_value': _(u'Ensure this value is less than or equal to %s.'),


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to