Re: Problem with Field errors

2009-03-29 Thread Matthew Somerville

Jack Orenstein wrote:
> On Mar 29, 2009, at 9:35 AM, Matthew Somerville wrote:

>> For more information, see
>> http://docs.djangoproject.com/en/dev/ref/forms/validation/
> 
> Thanks, that's really useful to know about. This works for most of  
> the additional validation I need to do, but doesn't fit so well for  
> the cross-field validation, (e.g. password and confirm_password  
> fields match). Or can I do that by overriding Form.is_valid?

 From the page I provided a link to: "* The Form subclass’s clean() 
method. This method can perform any validation that requires access to 
multiple fields from the form at once. This is where you might put in 
things to check that if field A is supplied, field B must contain a 
valid e-mail address and the like."

ATB,
Matthew

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



Re: Problem with Field errors

2009-03-29 Thread Jack Orenstein

On Mar 29, 2009, at 9:35 AM, Matthew Somerville wrote:

>
> Jack Orenstein wrote:
>> On Mar 28, 2009, at 12:26 PM, Daniel Roseman wrote:
>>
>>> On Mar 28, 4:14 pm, Jack Orenstein  wrote:
 My application needs to validate data from a from beyond the
 validation of Fields done by django. So in my form handler, I check
 Form.is_valid, and if that returns true, then I do my own  
 validation.
>
> If you have a field you need to perform more validation on, what you
> should do is give your Form subclass a clean_() method  
> which
> will be called automatically, and should raise a ValidationError if  
> the
> data doesn't validate (which will then put the error in the right  
> place
> for you). Then is_valid() will do Django and your validation together.
> For more information, see
> http://docs.djangoproject.com/en/dev/ref/forms/validation/

Thanks, that's really useful to know about. This works for most of  
the additional validation I need to do, but doesn't fit so well for  
the cross-field validation, (e.g. password and confirm_password  
fields match). Or can I do that by overriding Form.is_valid?

Jack


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



Re: Problem with Field errors

2009-03-29 Thread Matthew Somerville

Jack Orenstein wrote:
> On Mar 28, 2009, at 12:26 PM, Daniel Roseman wrote:
> 
>> On Mar 28, 4:14 pm, Jack Orenstein  wrote:
>>> My application needs to validate data from a from beyond the
>>> validation of Fields done by django. So in my form handler, I check
>>> Form.is_valid, and if that returns true, then I do my own validation.

If you have a field you need to perform more validation on, what you 
should do is give your Form subclass a clean_() method which 
will be called automatically, and should raise a ValidationError if the 
data doesn't validate (which will then put the error in the right place 
for you). Then is_valid() will do Django and your validation together. 
For more information, see 
http://docs.djangoproject.com/en/dev/ref/forms/validation/

>> Try self.form._errors['foobar'] instead.
> 
> That works, thank you.
> 
> Why does it work?

http://docs.djangoproject.com/en/dev/ref/forms/validation/#form-subclasses-and-modifying-field-errors
 
explains the _errors variable, but I don't think you need it in this case.

ATB,
Matthew

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



Re: Problem with Field errors

2009-03-28 Thread Jack Orenstein

On Mar 28, 2009, at 12:26 PM, Daniel Roseman wrote:

>
> On Mar 28, 4:14 pm, Jack Orenstein  wrote:
>> My application needs to validate data from a from beyond the
>> validation of Fields done by django. So in my form handler, I check
>> Form.is_valid, and if that returns true, then I do my own validation.
>> In case of errors, I attach an error message to the field, e.g.
>>
>>  self.form.fields['foobar'].errors = 'some error message'
>>
>> And then I redisplay the form. But the error message doesn't show up,
>> even though the template includes
>>
>>  {{ form.foobar.errors }}
>>
>> And through logging I have confirmed that the errors attribute of the
>> field has been set, right before the render_to_response call
>> containing the form. I'm guessing that this has something to do with
>> the fact that the form already passed the is_valid check.
>>
>> How can I force the form to become "invalid" again, once my own
>> validation detects errors?
>>
>> Jack Orenstein
>
> Try self.form._errors['foobar'] instead.

That works, thank you.

Why does it work?

Jack

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



Re: Problem with Field errors

2009-03-28 Thread Daniel Roseman

On Mar 28, 4:14 pm, Jack Orenstein  wrote:
> My application needs to validate data from a from beyond the  
> validation of Fields done by django. So in my form handler, I check  
> Form.is_valid, and if that returns true, then I do my own validation.  
> In case of errors, I attach an error message to the field, e.g.
>
>      self.form.fields['foobar'].errors = 'some error message'
>
> And then I redisplay the form. But the error message doesn't show up,  
> even though the template includes
>
>      {{ form.foobar.errors }}
>
> And through logging I have confirmed that the errors attribute of the  
> field has been set, right before the render_to_response call  
> containing the form. I'm guessing that this has something to do with  
> the fact that the form already passed the is_valid check.
>
> How can I force the form to become "invalid" again, once my own  
> validation detects errors?
>
> Jack Orenstein

Try self.form._errors['foobar'] instead.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Problem with Field errors

2009-03-28 Thread Jack Orenstein

My application needs to validate data from a from beyond the  
validation of Fields done by django. So in my form handler, I check  
Form.is_valid, and if that returns true, then I do my own validation.  
In case of errors, I attach an error message to the field, e.g.

 self.form.fields['foobar'].errors = 'some error message'

And then I redisplay the form. But the error message doesn't show up,  
even though the template includes

 {{ form.foobar.errors }}

And through logging I have confirmed that the errors attribute of the  
field has been set, right before the render_to_response call  
containing the form. I'm guessing that this has something to do with  
the fact that the form already passed the is_valid check.

How can I force the form to become "invalid" again, once my own  
validation detects errors?

Jack Orenstein


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