Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Form constructor callback doesn't allow to edit 'data' item #2

Closed
epper opened this Issue · 1 comment

2 participants

@epper

In views.validate you have:
def validate(request, args, *kwargs):
form_class = kwargs.pop('form_class')
extra_args_func = kwargs.pop('callback', lambda request, args, *kwargs: {})
kwargs = extra_args_func(request, args, *kwargs)
kwargs['data'] = request.POST
form = form_class(**kwargs)

I think it would be better to enable the callback function to change also the 'data' parameter passed to the form constructor.
A common use case is a Comment Applcation where for an anonymous user you have post fields with its data (nick, email, url) while for authenticated users you don't have that fields in the POST request and a callback function could simply specify them!
(This is the way the Comment Application bundled with django works)

So, I suggest to convert that code to something like that:
def validate(request, args, *kwargs):
form_class = kwargs.pop('form_class')
extra_args_func = kwargs.pop('callback', lambda request, args, *kwargs: {'data':request.POST})
kwargs = extra_args_func(request, args, *kwargs)
form = form_class(**kwargs)

@alex
Owner

Closed by 271f903. It is now possible to override the data parameter to the Form's constructor

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.