Django

Code

Ticket #3632 (closed: wontfix)

Opened 1 year ago

Last modified 3 months ago

initial values lost when calling newforms.form_for_instance() with a custom form arg

Reported by: ludo@qix.it Assigned to: thejaswi_puthraya
Component: django.newforms Version: SVN
Keywords: form_for_instance, decsprint01 Cc: gary.wilson@gmail.com, mtrier@gmail.com, larlet@gmail.com
Triage Stage: Ready for checkin Has patch: 1
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 0

Description

Initial values are lost when calling newforms.form_for_instance() with a custom form arg, eg

f = forms.form_for_instance(u) is ok

f = forms.form_for_instance(u, form=MyCustomForm) is not

The problem seems to be in DeclarativeFieldsMetaclass?.new where the 'base_fields' attribute gets wiped out when using a custom form class. A tentative patch, probably broken as my understanding of metaclass programming is nil, attached to this ticket.

Attachments

forms.diff (1.7 kB) - added by ludo@qix.it on 03/02/07 11:09:08.
tentative patch to newforms/forms.py
forms.2.diff (0.7 kB) - added by ludo@qix.it on 03/02/07 11:25:13.
revised patch
forms.py (0.8 kB) - added by ludo@qix.it on 03/02/07 13:40:38.
this one seems to work satisfactorily
forms.py.diff (0.8 kB) - added by empty <mtrier@gmail.com> on 12/01/07 08:22:27.
Updated patch against trunk 6781
forms.py.2.diff (0.8 kB) - added by empty <mtrier@gmail.com> on 12/01/07 08:41:10.
Updated because SortedDictFromList? was removed
forms.py.3.diff (2.6 kB) - added by empty <mtrier@gmail.com> on 12/01/07 14:46:41.
Patch with tests

Change History

03/02/07 11:09:08 changed by ludo@qix.it

  • attachment forms.diff added.

tentative patch to newforms/forms.py

03/02/07 11:25:13 changed by ludo@qix.it

  • attachment forms.2.diff added.

revised patch

03/02/07 13:31:11 changed by ludo@qix.it

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

None of the patches work, as the fields in both the custom form class and the one generated in form_for_instance() are the same.

03/02/07 13:40:38 changed by ludo@qix.it

  • attachment forms.py added.

this one seems to work satisfactorily

03/02/07 14:46:53 changed by ludo@qix.it

  • summary changed from initial values lost when calling newforms.form_for_instance() with a custom form arg [patch] to [patch] initial values lost when calling newforms.form_for_instance() with a custom form arg.

03/02/07 18:28:33 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Unreviewed to Accepted.

05/10/07 00:52:38 changed by Gary Wilson <gary.wilson@gmail.com>

  • cc set to gary.wilson@gmail.com.

11/25/07 19:14:30 changed by anonymous

  • cc changed from gary.wilson@gmail.com to gary.wilson@gmail.com, mtrier@gmail.com.

12/01/07 08:22:27 changed by david

  • cc changed from gary.wilson@gmail.com, mtrier@gmail.com to gary.wilson@gmail.com, mtrier@gmail.com, larlet@gmail.com.

12/01/07 08:22:27 changed by empty <mtrier@gmail.com>

  • attachment forms.py.diff added.

Updated patch against trunk 6781

12/01/07 08:27:47 changed by thejaswi_puthraya

  • owner changed from nobody to thejaswi_puthraya.

12/01/07 08:41:10 changed by empty <mtrier@gmail.com>

  • attachment forms.py.2.diff added.

Updated because SortedDictFromList? was removed

12/01/07 09:45:03 changed by thejaswi_puthraya

  • keywords changed from form_for_instance to form_for_instance, decsprint01.
  • stage changed from Accepted to Ready for checkin.

works with the patch of empty (Michael Trier).

12/01/07 14:46:41 changed by empty <mtrier@gmail.com>

  • attachment forms.py.3.diff added.

Patch with tests

12/01/07 22:07:53 changed by Simon G <dev@simon.net.nz>

  • summary changed from [patch] initial values lost when calling newforms.form_for_instance() with a custom form arg to initial values lost when calling newforms.form_for_instance() with a custom form arg.

02/14/08 01:19:35 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to wontfix.

I don't think this is worth fixing. It adds some extra code for a case that is better handled in another way (we already take base_fields from parent classes, so this introduces a *third* way of altering base_fields; it's getting a bit out of hand).

#6337 fixes the edge pieces of this for ModelForms, so the fix for this problem is "use ModelForms", rather than us adding some extra code that would only be used by form_for_instance() and thus is deprecated the moment it lands in trunk.

Sorry if that seems a little harsh for those wanting this feature, but it's a matter of trying to only introduce code that will live a long and healthy life.

02/14/08 06:56:50 changed by mtredinnick

(In [7112]) Fixed #6337. Refs #3632 -- Fixed ModelForms? subclassing, to the extent that it can be made to work.

This ended up being an almost complete rewrite of ModelForms?.new, but should be backwards compatible (although the text of one error message has changed, which is only user visible and only if you pass in invalid code).

Documentation updated, also.

This started out as a patch from semenov (many thanks!), but by the time all the problems were hammered out, little of the original was left. Still, it was a good starting point.


Add/Change #3632 (initial values lost when calling newforms.form_for_instance() with a custom form arg)




Change Properties
Action