Code

Opened 7 years ago

Closed 6 years ago

Last modified 3 years ago

#3639 closed (fixed)

use newforms in generic create_update view

Reported by: webograph <webograph@…> Owned by:
Component: Generic views Version: master
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: UI/UX:

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@…> 7 years ago.
r6635_create_update_newforms.diff (4.9 KB) - added by brosner 6 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 brosner 6 years ago.
patch with docs and tests
r6635_create_update_newforms_with_docs_and_tests2.diff (17.2 KB) - added by brosner 6 years ago.
revised docs and allowed fields to be customized
r6635_create_update_newforms3.diff (19.7 KB) - added by brosner 6 years ago.
created save_callback for custom saving of form data
create_update_newforms4.diff (21.6 KB) - added by brosner 6 years ago.
updated to r6963 and using ModelForm now. Backwards Incompatible.
create_update_newforms5.diff (22.2 KB) - added by brosner 6 years ago.
updated to r7140 and is now backward compatible by accepting a Model instance.
3639.diff (24.3 KB) - added by gwilson 6 years ago.
some updates to Brian's latest patch
3639.2008-07-12.patch (38.8 KB) - added by gwilson 6 years ago.
updated patch that also includes more removal of duplicated code and more tests

Download all attachments as: .zip

Change History (47)

Changed 7 years ago by webograph <webograph@…>

comment:1 Changed 7 years ago by ubernostrum

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 7 years ago by SmileyChris

  • Triage 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.

comment:3 Changed 7 years ago by webograph <webograph@…>

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 Changed 7 years ago by mtredinnick

  • Triage 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.

comment:5 Changed 7 years ago by anonymous

  • Cc elsdoerfer@… added

Changed 6 years ago by brosner

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

comment:6 Changed 6 years ago by brosner

  • 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 Changed 6 years ago by Thomas Güttler (Home) <guettli.djangotrac@…>

  • Cc hv@… added

Changed 6 years ago by brosner

patch with docs and tests

comment:8 Changed 6 years ago by brosner

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

Changed 6 years ago by brosner

revised docs and allowed fields to be customized

Changed 6 years ago by brosner

created save_callback for custom saving of form data

comment:9 Changed 6 years ago by niels

  • Cc niels.busch@… added

comment:10 Changed 6 years ago 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.

comment:11 Changed 6 years ago by brosner

  • Owner changed from nobody to brosner
  • Status changed from new to assigned

Changed 6 years ago by brosner

updated to r6963 and using ModelForm now. Backwards Incompatible.

comment:12 Changed 6 years ago 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?

Changed 6 years ago by brosner

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

comment:13 Changed 6 years ago by msaelices

  • Cc msaelices@… added

comment:14 Changed 6 years ago by brosner

  • Version changed from SVN to newforms-admin

comment:15 Changed 6 years ago 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.

comment:16 Changed 6 years ago 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?

comment:17 follow-up: Changed 6 years ago 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.

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

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 Changed 6 years ago by brosner

  • Owner brosner deleted
  • Status changed from assigned to new

comment:20 Changed 6 years ago by Samuel Cormier-Iijima <sciyoshi@…>

  • Cc sciyoshi@… added

comment:21 Changed 6 years ago by anonymous

  • Cc ganeshpulsars@… added

comment:22 Changed 6 years ago by mir

  • Cc mir@… added

comment:23 Changed 6 years ago by Jeff Forcier <jeff@…>

  • 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 Changed 6 years ago by brosner

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

comment:25 Changed 6 years ago by Jeff Forcier <jeff@…>

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 Changed 6 years ago by programmerq

  • Cc jefferya@… added

comment:27 Changed 6 years ago by jacob

  • milestone set to 1.0 alpha

Changed 6 years ago by gwilson

some updates to Brian's latest patch

comment:28 follow-up: Changed 6 years ago by darkpixel

  • 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 Changed 6 years ago by das

  • Cc das@… added

Changed 6 years ago by gwilson

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

comment:30 Changed 6 years ago by gwilson

  • Patch needs improvement unset
  • Triage 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.

comment:31 in reply to: ↑ 28 Changed 6 years ago by gwilson

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 Changed 6 years ago by Jeff Forcier <jeff@…>

  • Cc jeff@… removed

comment:33 Changed 6 years ago by niels

  • Cc niels.busch@… removed

comment:34 Changed 6 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:35 Changed 6 years ago by gwilson

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

comment:36 Changed 6 years ago by guettli

  • Cc hv@… removed

comment:37 Changed 6 years ago by das

  • Cc das@… removed

comment:38 Changed 3 years ago by jacob

  • milestone 1.0 alpha deleted

Milestone 1.0 alpha deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.