1. Jesper Nøhr
  2. django-piston
Issue #145 resolved

@validate does not attach the form to the request object

Anonymous created an issue

{{{

!python

def validate(v_form, operation='POST'): Николай Хаверев def wrap(f, self, request, a, *kwa): form = v_form(getattr(request, operation))

    if form.is_valid():
        #attach it
        request.form=form
        return f(self, request, *a, **kwa)
    else:
        raise FormValidationError(form)
return wrap

}}}

Comments (7)

  1. José Manuel Fardello

    There are some references to this behavior in the docs samples (but piston.utils.validate does not attach the form ) , it could be also useful to attach the request to the form, that way you can access things like self.request.user.get_profile() while cleaning fields.

    this is what I use:

    def validate(v_form, operation='POST'):
        @decorator
        def wrap(f, self, request, *a, **kwa):
            form = v_form(getattr(request, operation))
    
            form.request = request
            if form.is_valid():
                del form.request
                request.form=form
                return f(self, request, *a, **kwa)
            else:
                raise FormValidationError(form)
        return wrap
    
    
  2. Log in to comment