#3639 closed (fixed)
use newforms in generic create_update view
Reported by: | 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)
Change History (47)
by , 18 years ago
Attachment: | create_update__newforms.diff added |
---|
comment:1 by , 18 years ago
comment:2 by , 18 years ago
Triage Stage: | Unreviewed → 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 by , 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 , 18 years ago
Triage Stage: | Ready for checkin → 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 by , 17 years ago
Cc: | added |
---|
by , 17 years ago
Attachment: | r6635_create_update_newforms.diff added |
---|
updated to trunk. fixed several issues with last patch and added form
and
formfield_callback
overrides.
comment:6 by , 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 , 17 years ago
Cc: | added |
---|
by , 17 years ago
Attachment: | r6635_create_update_newforms_with_docs_and_tests.diff added |
---|
patch with docs and tests
comment:8 by , 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 , 17 years ago
Attachment: | r6635_create_update_newforms_with_docs_and_tests2.diff added |
---|
revised docs and allowed fields
to be customized
by , 17 years ago
Attachment: | r6635_create_update_newforms3.diff added |
---|
created save_callback
for custom saving of form data
comment:9 by , 17 years ago
Cc: | added |
---|
comment:10 by , 17 years ago
comment:11 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 17 years ago
Attachment: | create_update_newforms4.diff added |
---|
updated to r6963 and using ModelForm now. Backwards Incompatible.
comment:12 by , 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 , 17 years ago
Attachment: | create_update_newforms5.diff added |
---|
updated to r7140 and is now backward compatible by accepting a Model
instance.
comment:13 by , 17 years ago
Cc: | added |
---|
comment:14 by , 17 years ago
Version: | SVN → newforms-admin |
---|
comment:15 by , 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 , 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?
follow-up: 18 comment:17 by , 17 years ago
Version: | newforms-admin → 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 by , 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 , 17 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:20 by , 17 years ago
Cc: | added |
---|
comment:21 by , 17 years ago
Cc: | added |
---|
comment:22 by , 17 years ago
Cc: | added |
---|
comment:23 by , 17 years ago
Cc: | 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 , 17 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 , 17 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 , 17 years ago
Cc: | added |
---|
comment:27 by , 17 years ago
milestone: | → 1.0 alpha |
---|
follow-up: 31 comment:28 by , 16 years ago
Patch needs improvement: | set |
---|
I applied this patch to svn 7871.
Two things I ran into:
- A patch chunk failed to apply to docs (understandable since the docs have changed since the patch has been uploaded)
- 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 , 16 years ago
Cc: | added |
---|
by , 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 , 16 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → 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 by , 16 years ago
Replying to darkpixel:
- 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 , 16 years ago
Cc: | removed |
---|
comment:33 by , 16 years ago
Cc: | removed |
---|
comment:34 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:35 by , 16 years ago
comment:36 by , 16 years ago
Cc: | removed |
---|
comment:37 by , 16 years ago
Cc: | removed |
---|
I believe the switchover for generic views going to newforms will be sometime after the 0.96 release.