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

Closed
epper opened this Issue Jul 25, 2009 · 1 comment

Comments

Projects
None yet
2 participants

epper commented Jul 25, 2009

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)

Owner

alex commented Aug 6, 2009

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

pombredanne pushed a commit to pombredanne/django-ajax-validation that referenced this issue Nov 26, 2012

Merge pull request #2 from goinnn/master
Now you can validate a form until the current input

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment