Package: django-cbv-formpreview
UsageI will write better documentation shortly, but for now see Django’s
documentation on itsversion of this class.This project is just a forkDjango’s FormPreviewclass. There are a few basic differences when using
django-cbv-formpreview’s version of the class:Specify the form you wish to use by settingform_classon your
subclass. This is instead of constructing aFormPreviewwith
the form class (i.e. don’t doMyFormPreview(MyForm))Include it in your URLconf just as you would a normal class-based
view (i.e.MyFormPreview.as_view())You still need to override thedonemethod, but it only takes a
cleanedformas an argument. Django’s version takes anHttpRequestobject and the form’scleaned_data. Like all
class-based views, the currentHttpRequestis available as an
instance attribute (i.e.self.request).Theprocess_previewmethod is still there, but it takes aformand thecontextit will pass to the template. It is no
longer passed anHttpRequestobject for the same reason as
above.Along with the above backwards incompatibile changes that affect
publicly documented behavior, a comment in the source code
suggested a few methods that might be useful to override. The methodsget_initial,security_hash, andfailed_hashused to take
anHttpRequestas an argument but no longer do for the same
reason stated above. A few other changes to note:process_paramshas been removed. Theargsandkwargspassed to the view are available as instance attributes with the same
names. If you need to do something with them before the view is
processed, overridedispatchand be sure to return a call to the
parentsdispatchmethod (i.e.return super(MyFormPreview,self).dispatch(request,*args, **kwargs).get_auto_idhas also been removed. Overrideget_form_kwargsif you need it.Please let me know if I’ve missed anything.BackgroundTheFormPreviewclass from thecontrib.formtoolsapp is a
class based view that’s been in Django for over 5 years. Originally
written by Adrian Holovaty, it hasn’t changed significantly since its
release.Starting in version 1.3, Django has a “blessed” version of class based
views. This package contains an updated version ofFormPreviewthat inherits from the newFormViewclass. This enables a
consistent API for class based views in Django. Of particular
use are the methods provided by theFormMixinclass, from whichFormViewinherits. For example, theget_formmethod gives you
control over the instantiation of the form class. This allows you to
construct an instance with non-standard arguments which was the
original motivation of the patch.I originally strove for backwards compatibility but after using this
in production, decided it wasn’t worth it. The final straw was when
I needed to call thesavemethod on a form indone. Django’sFormPreviewonly passedcleaned_dataand I didn’t want to
reconstruct the form as recleaning it would unnecessarily hit the
database.I previously filed aticketon Django’s trac to include the original backwards compatibile version
ofdjango-cbv-formpreviewin Django 1.4. Now that I’ve broken
backwards compatibility, I’m not sure how the core devs will respond
to it. I personally feel that few people actually use this
functionality and would therefore have minimal impact on the community.