Override __init__ for the Form, passing it the request object and
store it. Access it in .clean method.

On Jan 12, 10:45 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I also just realized that the reason clean() wouldn't work when I
> tried to pass it the request as an argument is simply because this
> required me to call clean() by itself and thus the errors raised
> within it aren't properly inherited (and thus reflected when the form
> is reloaded) when clean() is called outside of is_valid()
>
> On Jan 11, 9:24 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > Thanks Karen,
>
> > I did initially want to raise it in the clean method but what I'm
> > trying to do this is validate that cookies are enabled thus requiring
> > access to the request object. I first tried to pass it to clean which
> > really doesn't seem like a clean way to do it - no pun intended -
> > anyway, since usually I would just want clean() to be called when I
> > called form.is_valid() and I cannot pass any arguments that way, but
> > in any case that didn't really work out (def clean(self,request) would
> > complain about the number of arguments being too many - 3 instead of 2
> > - when I attempted to pass in the request object) Granted, I didn't
> > try this for as long as the other method.
>
> > If you have suggestions for how to pass arguments to clean() in a
> > better way that would be another workaround for this issue. Basically
> > I wanted to raise cookie errors from within the form handling so I
> > didnt have to redirect to another page or implement some custom thing
> > in the template. (I am however open to doing this if it is the better
> > solution, I'm just not sure what best practice here would be).
>
> > On Jan 11, 8:21 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
>
> > > On Jan 11, 2008 10:49 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > > > I want to manually insert an error into a form from the view using
> > > > f.errors (where f is the form in question). For a specific field this
> > > > is easy (f.errors['fieldname'] = u'my error here') but I can't seem to
> > > > figure out how to make non field errors work. Is there a special
> > > > dictionary entry for non field errors, or some other way to do this. I
> > > > had a look at the django code but didn't get much further here. Any
> > > > suggestions are appreciated.
>
> > > Take a look at the doc for the Form subclass's clean() method here:
>
> > >http://www.djangoproject.com/documentation/newforms/#custom-form-and-...
>
> > > It would be cleaner to raise the error in a clean() method, but I think 
> > > the
> > > doc includes the information you need to manipulate it yourself if you
> > > really want to.  (Note you can also customize the error messages for 
> > > fields,
> > > which could get around having to manipulate f.errors['fieldname'] 
> > > directly,
> > > see:http://www.djangoproject.com/documentation/newforms/#error-messages.)
>
> > > Karen
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to