Django

Code

Ticket #3639 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

use newforms in generic create_update view

Reported by: webograph <webograph@eml.cc> Assigned to:
Milestone: 1.0 alpha Component: Generic views
Version: SVN Keywords: newforms
Cc: elsdoerfer@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jefferya@programmerq.net Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

create_update__newforms.diff (3.5 kB) - added by webograph <webograph@eml.cc> on 03/02/07 17:09:36.
r6635_create_update_newforms.diff (4.9 kB) - added by brosner on 10/31/07 15:34:52.
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 brosner on 10/31/07 23:07:10.
patch with docs and tests
r6635_create_update_newforms_with_docs_and_tests2.diff (17.2 kB) - added by brosner on 11/02/07 15:12:30.
revised docs and allowed fields to be customized
r6635_create_update_newforms3.diff (19.7 kB) - added by brosner on 11/02/07 19:13:33.
created save_callback for custom saving of form data
create_update_newforms4.diff (21.6 kB) - added by brosner on 12/20/07 18:47:09.
updated to r6963 and using ModelForm? now. Backwards Incompatible.
create_update_newforms5.diff (22.2 kB) - added by brosner on 02/21/08 22:07:46.
updated to r7140 and is now backward compatible by accepting a Model instance.
3639.diff (24.3 kB) - added by gwilson on 06/16/08 15:48:34.
some updates to Brian's latest patch
3639.2008-07-12.patch (38.8 kB) - added by gwilson on 07/12/08 16:37:11.
updated patch that also includes more removal of duplicated code and more tests

Change History

03/02/07 17:09:36 changed by webograph <webograph@eml.cc>

  • attachment create_update__newforms.diff added.

03/02/07 19:03:25 changed by ubernostrum

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

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

04/10/07 22:56:37 changed by SmileyChris

  • stage changed from Unreviewed to Ready 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.

04/11/07 05:05:01 changed by webograph <webograph@eml.cc>

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.

04/25/07 04:01:24 changed by mtredinnick

  • stage changed from Ready for checkin to Accepted.

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.

07/06/07 19:45:08 changed by anonymous

  • cc set to elsdoerfer@gmail.com.

10/31/07 15:34:52 changed by brosner

  • attachment r6635_create_update_newforms.diff added.

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

10/31/07 15:37:18 changed by brosner

  • needs_docs set to 1.
  • needs_tests set to 1.

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.

10/31/07 16:29:39 changed by Thomas Güttler (Home) <guettli.djangotrac@thomas-guettler.de>

  • cc changed from elsdoerfer@gmail.com to elsdoerfer@gmail.com, hv@tbz-pariv.de.

10/31/07 23:07:10 changed by brosner

  • attachment r6635_create_update_newforms_with_docs_and_tests.diff added.

patch with docs and tests

10/31/07 23:10:21 changed by brosner

  • needs_docs deleted.
  • needs_tests deleted.

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.

11/02/07 15:12:30 changed by brosner

  • attachment r6635_create_update_newforms_with_docs_and_tests2.diff added.

revised docs and allowed fields to be customized

11/02/07 19:13:33 changed by brosner

  • attachment r6635_create_update_newforms3.diff added.

created save_callback for custom saving of form data

11/17/07 18:15:48 changed by niels

  • cc changed from elsdoerfer@gmail.com, hv@tbz-pariv.de to elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com.

12/01/07 12:48:33 changed by brosner

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.

12/10/07 18:56:52 changed by brosner

  • owner changed from nobody to brosner.
  • status changed from new to assigned.

12/20/07 18:47:09 changed by brosner

  • attachment create_update_newforms4.diff added.

updated to r6963 and using ModelForm? now. Backwards Incompatible.

12/20/07 18:48:57 changed by brosner

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?

02/21/08 22:07:46 changed by brosner

  • attachment create_update_newforms5.diff added.

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

02/22/08 12:00:50 changed by msaelices

  • cc changed from elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com to elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es.

03/07/08 09:12:26 changed by brosner

  • version changed from SVN to newforms-admin.

03/07/08 09:18:52 changed by mtredinnick

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.

03/07/08 09:28:00 changed by brosner

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?

(follow-up: ↓ 18 ) 03/07/08 09:33:19 changed by mtredinnick

  • version changed from newforms-admin to SVN.

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 ) 03/07/08 10:57:16 changed by Karen Tracey <kmtracey@gmail.com>

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.

04/16/08 15:39:03 changed by brosner

  • owner deleted.
  • status changed from assigned to new.

05/02/08 20:25:14 changed by Samuel Cormier-Iijima <sciyoshi@gmail.com>

  • cc changed from elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es to elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com.

05/11/08 09:01:25 changed by anonymous

  • cc changed from elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com to elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com.

06/09/08 01:03:55 changed by mir

  • cc changed from elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com to elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de.

06/09/08 20:09:20 changed by Jeff Forcier <jeff@bitprophet.org>

  • cc changed from elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de to elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jeff@bitprophet.org.

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.

06/09/08 20:18:03 changed by brosner

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

06/09/08 20:20:23 changed by Jeff Forcier <jeff@bitprophet.org>

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...:)

06/12/08 11:49:51 changed by programmerq

  • cc changed from elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jeff@bitprophet.org to elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jeff@bitprophet.org, jefferya@programmerq.net.

06/16/08 12:11:40 changed by jacob

  • milestone set to 1.0 alpha.

06/16/08 15:48:34 changed by gwilson

  • attachment 3639.diff added.

some updates to Brian's latest patch

(follow-up: ↓ 31 ) 07/08/08 22:36:24 changed by darkpixel

  • needs_better_patch set to 1.

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!

07/09/08 07:32:14 changed by das

  • cc changed from elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jeff@bitprophet.org, jefferya@programmerq.net to elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jeff@bitprophet.org, jefferya@programmerq.net, das@snt.utwente.nl.

07/12/08 16:37:11 changed by gwilson

  • attachment 3639.2008-07-12.patch added.

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

07/12/08 16:43:01 changed by gwilson

  • needs_better_patch deleted.
  • stage changed from Accepted to Ready 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 ) 07/13/08 15:36:20 changed by gwilson

Replying to darkpixel:

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.

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

07/13/08 15:39:54 changed by Jeff Forcier <jeff@bitprophet.org>

  • cc changed from elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jeff@bitprophet.org, jefferya@programmerq.net, das@snt.utwente.nl to elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jefferya@programmerq.net, das@snt.utwente.nl.

07/13/08 16:20:11 changed by niels

  • cc changed from elsdoerfer@gmail.com, hv@tbz-pariv.de, niels.busch@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jefferya@programmerq.net, das@snt.utwente.nl to elsdoerfer@gmail.com, hv@tbz-pariv.de, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jefferya@programmerq.net, das@snt.utwente.nl.

07/18/08 14:45:01 changed by jacob

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

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

07/18/08 18:52:18 changed by gwilson

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

09/04/08 09:54:34 changed by guettli

  • cc changed from elsdoerfer@gmail.com, hv@tbz-pariv.de, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jefferya@programmerq.net, das@snt.utwente.nl to elsdoerfer@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jefferya@programmerq.net, das@snt.utwente.nl.

09/11/08 11:04:02 changed by das

  • cc changed from elsdoerfer@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jefferya@programmerq.net, das@snt.utwente.nl to elsdoerfer@gmail.com, msaelices@yaco.es, sciyoshi@gmail.com, ganeshpulsars@gmail.com, mir@noris.de, jefferya@programmerq.net.

Add/Change #3639 (use newforms in generic create_update view)




Change Properties
Action