Opened 17 years ago

Closed 16 years ago

Last modified 16 years ago

#3632 closed (wontfix)

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

Reported by: ludo@… Owned by: Thejaswi Puthraya
Component: Forms Version: dev
Severity: Keywords: form_for_instance, decsprint01
Cc: gary.wilson@…, mtrier@…, larlet@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 (6)

forms.diff (1.7 KB ) - added by ludo@… 17 years ago.
tentative patch to newforms/forms.py
forms.2.diff (720 bytes ) - added by ludo@… 17 years ago.
revised patch
forms.py (808 bytes ) - added by ludo@… 17 years ago.
this one seems to work satisfactorily
forms.py.diff (800 bytes ) - added by empty <mtrier@…> 16 years ago.
Updated patch against trunk 6781
forms.py.2.diff (792 bytes ) - added by empty <mtrier@…> 16 years ago.
Updated because SortedDictFromList was removed
forms.py.3.diff (2.6 KB ) - added by empty <mtrier@…> 16 years ago.
Patch with tests

Download all attachments as: .zip

Change History (17)

by ludo@…, 17 years ago

Attachment: forms.diff added

tentative patch to newforms/forms.py

by ludo@…, 17 years ago

Attachment: forms.2.diff added

revised patch

comment:1 by ludo@…, 17 years ago

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.

by ludo@…, 17 years ago

Attachment: forms.py added

this one seems to work satisfactorily

comment:2 by ludo@…, 17 years ago

Summary: initial values lost when calling newforms.form_for_instance() with a custom form arg [patch][patch] initial values lost when calling newforms.form_for_instance() with a custom form arg

comment:3 by Simon G. <dev@…>, 17 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Gary Wilson <gary.wilson@…>, 17 years ago

Cc: gary.wilson@… added

comment:5 by anonymous, 16 years ago

Cc: mtrier@… added

by empty <mtrier@…>, 16 years ago

Attachment: forms.py.diff added

Updated patch against trunk 6781

comment:6 by David Larlet, 16 years ago

Cc: larlet@… added

comment:7 by Thejaswi Puthraya, 16 years ago

Owner: changed from nobody to Thejaswi Puthraya

by empty <mtrier@…>, 16 years ago

Attachment: forms.py.2.diff added

Updated because SortedDictFromList was removed

comment:8 by Thejaswi Puthraya, 16 years ago

Keywords: decsprint01 added
Triage Stage: AcceptedReady for checkin

works with the patch of empty (Michael Trier).

by empty <mtrier@…>, 16 years ago

Attachment: forms.py.3.diff added

Patch with tests

comment:9 by Simon G <dev@…>, 16 years ago

Summary: [patch] initial values lost when calling newforms.form_for_instance() with a custom form arginitial values lost when calling newforms.form_for_instance() with a custom form arg

comment:10 by Malcolm Tredinnick, 16 years ago

Resolution: wontfix
Status: newclosed

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.

comment:11 by Malcolm Tredinnick, 16 years ago

(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.

Note: See TracTickets for help on using tickets.
Back to Top