Open gchp opened 10 years ago
Probably this is of interest for you. I wrote a Mixin which adds the preview functionality to the default Django-CBVs. Maybe something like this could additionally (or instead the current preview) be included into the formtools? I put the mixin on django-snippets just a few minutes ago: https://djangosnippets.org/snippets/10475/
So why is this one abandoned?
I think that the current implementation is actually a dangerous one because it's not thread safe storing the state in the instance while the instance is the same for all the request to a view?
there wasn't any contributor to complete it
This issue was originally submitted on Trac (#16174). Please see that ticket for the original conversation.
NOTE: There are a few patches attached to the Trac ticket which may be useful.
I used the FormPreview class in
formtools.preview
for the first time this week. After working with class based views for a while, I really missed methods likeget_form
for custom form instantiation. Recently, the form wizard machinery (which is much more complex) got a class-based views update (#9200) so I decided to update the FormPreview class as well. It usesdjango.views.generic.FormView
and it's on a Django branch on my Github account. (https://github.com/ryankask/django/blob/cbv-formpreview/django/contrib/formtools/preview.py -- I've also attached a diff based on the Django Github mirror which I am pretty sure is acceptable.In order to maintain 100% compatibility, there are some issues to note:
get_context
whereas the class based views useget_context_data
. I've made it so both can be used but if backwards compatibility can be broken, it would be better to only useget_context_data
.__call__
so it could be easily instantiated with a form in a urlconf. I moved the important code to dispatch and__call__
just returns a call to dispatch.failed_hash
method, which isn't documented, falls under a section in the code which says "METHODS SUBCLASSES MIGHT OVERRIDE IF APPROPRIATE." I left the ability to call that method and it just wrapspost
and sets the current stage topreview
.get_initial
,process_preview
, andsecurity_hash
, which all fall under the "override if you need to" section only documented in the code, used to take a request as an argument. They all still do. The methods that were marked "don't touch" now use the instance'srequest
.If backwards compatibility doesn't need to be maintained, the code can be cleaned up a little more.
Anyway, any comments on the patch would be much appreciated and I'd update the docs if devs think it's okay.
By the way, if none of this is acceptable, the test
formtools.PreviewTests.test_form_submit_bad_hash
needs to be fixed (it is in my patch).self.client.post('/previewpreview/', self.test_data)
results in a 404 so the next assertion that some text isn't in the template passes when it shouldn't.