Opened 18 years ago

Closed 16 years ago

Last modified 13 years ago

#3639 closed (fixed)

use newforms in generic create_update view

Reported by: webograph <webograph@…> Owned by:
Component: Generic views Version: dev
Severity: Keywords: newforms
Cc: elsdoerfer@…, msaelices@…, sciyoshi@…, ganeshpulsars@…, mir@…, jefferya@… 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

in order to make newforms available to the generic create_update view (as it is planned, i suppose), i modified the create_update.py to make use of newforms. i have not found any discussion on this, which will definitely have to take place, but as of already using it myself, i hope it can be useful for others and maybe be the base for the final change.

existing templates will probably still work but might break.

i'm not sure what the new_data = request.POST.copy() (2x) was exactly intended to prevent, so i left them in place; maybe they are not necessary any more.

Attachments (9)

create_update__newforms.diff (3.5 KB ) - added by webograph <webograph@…> 18 years ago.
r6635_create_update_newforms.diff (4.9 KB ) - added by Brian Rosner 17 years ago.
updated to trunk. fixed several issues with last patch and added form and formfield_callback overrides.
r6635_create_update_newforms_with_docs_and_tests.diff (16.6 KB ) - added by Brian Rosner 17 years ago.
patch with docs and tests
r6635_create_update_newforms_with_docs_and_tests2.diff (17.2 KB ) - added by Brian Rosner 17 years ago.
revised docs and allowed fields to be customized
r6635_create_update_newforms3.diff (19.7 KB ) - added by Brian Rosner 17 years ago.
created save_callback for custom saving of form data
create_update_newforms4.diff (21.6 KB ) - added by Brian Rosner 17 years ago.
updated to r6963 and using ModelForm now. Backwards Incompatible.
create_update_newforms5.diff (22.2 KB ) - added by Brian Rosner 17 years ago.
updated to r7140 and is now backward compatible by accepting a Model instance.
3639.diff (24.3 KB ) - added by Gary Wilson 16 years ago.
some updates to Brian's latest patch
3639.2008-07-12.patch (38.8 KB ) - added by Gary Wilson 16 years ago.
updated patch that also includes more removal of duplicated code and more tests

Download all attachments as: .zip

Change History (47)

by webograph <webograph@…>, 18 years ago

comment:1 by James Bennett, 18 years ago

I believe the switchover for generic views going to newforms will be sometime after the 0.96 release.

comment:2 by Chris Beaven, 18 years ago

Triage Stage: UnreviewedReady for checkin

Just in case it's useful for newforms branch I'll mark this ready for checkin for Adrian to have a look at.

comment:3 by webograph <webograph@…>, 18 years ago

i checked that request.POST.copy() issue, by the way. it's not required by the forms procedure any more, but as data from request.FILE is added to the data dictionary, the copy() is still required.

comment:4 by Malcolm Tredinnick, 18 years ago

Triage Stage: Ready for checkinAccepted

Isn't this dependent on form_for_instance() being able to handle things like FileField fields?

Please move back to "ready for checkin" if I've missed something, but I think it's still missing some dependencies.

comment:5 by anonymous, 17 years ago

Cc: elsdoerfer@… added

by Brian Rosner, 17 years ago

updated to trunk. fixed several issues with last patch and added form and formfield_callback overrides.

comment:6 by Brian Rosner, 17 years ago

Needs documentation: set
Needs tests: set

I have attached a patch that fixes several issues with the last one. Uses newforms correctly. This patch applies cleanly against trunk at r6635. I added form and formfield_callback overrides to allow for customization of the form. I removed the follow kwarg as it is not needed any longer with newforms. I am currently working on some tests and revised docs.

comment:7 by Thomas Güttler (Home) <guettli.djangotrac@…>, 17 years ago

Cc: hv@… added

by Brian Rosner, 17 years ago

patch with docs and tests

comment:8 by Brian Rosner, 17 years ago

Needs documentation: unset
Needs tests: unset

I have completed writing the tests and revised the docs. For some reason Trac doesn't seem to know how to display my diff.

This change does introduce a backward incompatibility in the templates that is similar to those who move to newforms anyways. Let me know if I missed anything or need to revise anything in the patch.

by Brian Rosner, 17 years ago

revised docs and allowed fields to be customized

by Brian Rosner, 17 years ago

created save_callback for custom saving of form data

comment:9 by Niels Sandholt Busch, 17 years ago

Cc: niels.busch@… added

comment:10 by Brian Rosner, 17 years ago

I want to point out that I have verified the patch against latest trunk r6798. However, this patch is pending the ModelForm feature found in #6042.

comment:11 by Brian Rosner, 17 years ago

Owner: changed from nobody to Brian Rosner
Status: newassigned

by Brian Rosner, 17 years ago

updated to r6963 and using ModelForm now. Backwards Incompatible.

comment:12 by Brian Rosner, 17 years ago

I have attached a new patch that is now working with ModelForm. To do this I made this change as backwards incompatible. I think that should not be the case and use a helper function to dynamically create the ModelForm from the model at run-time. This is found in the newforms-admin branch (modelform_for_model) so it might be good to port it to trunk? What do people think about this?

by Brian Rosner, 17 years ago

updated to r7140 and is now backward compatible by accepting a Model instance.

comment:13 by Manuel Saelices, 17 years ago

Cc: msaelices@… added

comment:14 by Brian Rosner, 17 years ago

Version: SVNnewforms-admin

comment:15 by Malcolm Tredinnick, 17 years ago

Why has this been moved to newforms_admin? Generic views aren't used in admin are they? If not, then it's a purely trunk thing and we should avoid doing it on the branch.

comment:16 by Brian Rosner, 17 years ago

I may have got the wrong impression that newforms-admin was meant for all newforms conversions. Is that not true or is this an exception to that?

comment:17 by Malcolm Tredinnick, 17 years ago

Version: newforms-adminSVN

Newforms admin is for converting admin to use newforms. Like it says in the branch name.

This patch will be committed to trunk eventually, don't worry. But I, personally, haven't done it yet because of the massive backwards-incompatibility it introduces, making timing important. It should definitely be independent of newforms admin, though, so that people don't have unrelated upheavals going on at once.

in reply to:  17 comment:18 by Karen Tracey <kmtracey@…>, 17 years ago

Replying to mtredinnick:

Newforms admin is for converting admin to use newforms. Like it says in the branch name.

The question of the scope of the newforms-admin branch also came up when someone starting looking at converting auth to newforms. Russell's reply here:

http://groups.google.com/group/django-developers/msg/f5e0a3c5a227c123

may be where people are getting the idea that all remaining newforms conversions should be done first in the context of the newforms-admin branch. Not trying to say one way or the other where things should be done, just trying to point out where the confusion may be coming from.

comment:19 by Brian Rosner, 17 years ago

Owner: Brian Rosner removed
Status: assignednew

comment:20 by Samuel Cormier-Iijima <sciyoshi@…>, 17 years ago

Cc: sciyoshi@… added

comment:21 by anonymous, 16 years ago

Cc: ganeshpulsars@… added

comment:22 by Michael Radziej, 16 years ago

Cc: mir@… added

comment:23 by Jeff Forcier <jeff@…>, 16 years ago

Cc: jeff@… added

Pedantic note, should this ticket's description be updated to reflect the more, er, generic goal of having all generic views use newforms, not just create_update? Certainly it's now implied by VersionOneFeatures that this is "the" ticket for such things.

comment:24 by Brian Rosner, 16 years ago

The create_update views are the only ones that use forms. It would make sense that they would be the only ones :)

comment:25 by Jeff Forcier <jeff@…>, 16 years ago

That's a really good point, I've been thinking too much about generic views as a single package and that didn't really occur to me. I clearly need to avoid browsing Trac tickets after overly-long work days...:)

comment:26 by Jeff Anderson, 16 years ago

Cc: jefferya@… added

comment:27 by Jacob, 16 years ago

milestone: 1.0 alpha

by Gary Wilson, 16 years ago

Attachment: 3639.diff added

some updates to Brian's latest patch

comment:28 by Aaron C. de Bruyn, 16 years ago

Patch needs improvement: set

I applied this patch to svn 7871.
Two things I ran into:

  1. A patch chunk failed to apply to docs (understandable since the docs have changed since the patch has been uploaded)
  2. The post_save_redirect parameter to create_object is supposed to be optional, however when you do not supply it you get an error after saving the form:

ImproperlyConfigured at /your/url/new/
No URL to redirect to from generic create view.

Supplying a post_save_redirect parameter will cause it to redirect correctly.

I can't wait for these patches to get applied to trunk!

comment:29 by das, 16 years ago

Cc: das@… added

by Gary Wilson, 16 years ago

Attachment: 3639.2008-07-12.patch added

updated patch that also includes more removal of duplicated code and more tests

comment:30 by Gary Wilson, 16 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

I've taken Brian's patch and added the following:

  • Brought back the model argument, but made it optional. We now check that one of model or form_class is given. form_class, if given, overrides the default ModelForm created from model.
  • Issue a deprecation warning if the follow parameter is used, letting people know that generic views now use newforms and to use form_class if a custom form is needed.
  • Fixed an error I was getting in the tests when using "model = model" in the inner Meta class (works fine in my shell, but gives me "model not defined" errors when I run the tests) by introducing a tmp_model variable.
  • Added a GenericViewError class and made a couple AttributeErrors use this Exception class instead since AttributeError doesn't really fit.
  • Added a get_model_and_form_class helper function to remove duplicate ModelForm-generating code.
  • Finished off the test_create_custom_save_article test with a custom_create view that passes a custom form to the create_update generic view.
  • Factored out some duplicated code into the apply_extra_context, redirect, and lookup_object functions.
  • Added more tests for the post_save_redirect parameter and models with/without a get_absolute_url method.

The first two points were discussed here.

in reply to:  28 comment:31 by Gary Wilson, 16 years ago

Replying to darkpixel:

  1. The post_save_redirect parameter to create_object is supposed to be optional, however when you do not supply it you get an error after saving the form:

ImproperlyConfigured at /your/url/new/
No URL to redirect to from generic create view.

With no post_save_redirect specified and no get_absolute_url method defined on your model, this error will indeed get raised.

comment:32 by Jeff Forcier <jeff@…>, 16 years ago

Cc: jeff@… removed

comment:33 by Niels Sandholt Busch, 16 years ago

Cc: niels.busch@… removed

comment:34 by Jacob, 16 years ago

Resolution: fixed
Status: newclosed

(In [7952]) Fixed #3639: updated generic create_update views to use newforms. This is a backwards-incompatible change.

comment:35 by Gary Wilson, 16 years ago

(In [7966]) Refs #3639 -- Minor docstring correction, it's a function not a method.

comment:36 by Thomas Güttler, 16 years ago

Cc: hv@… removed

comment:37 by das, 16 years ago

Cc: das@… removed

comment:38 by Jacob, 13 years ago

milestone: 1.0 alpha

Milestone 1.0 alpha deleted

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