How to wrap Django FormPreview in a view

I have a situation (the shopping cart checkout sequence) where the workflow used in the application to create Django FormPreview looks perfect, except that I need to have some presentation logic before I call it (I cannot call the sequence check if the basket is empty, for example). From docs, it looks like you are calling FormPreview directly from urlconf like this:

(r'^post/$', SomeModelFormPreview(SomeModelForm))

... and it calls the overridden done () method for FormPreview directly (without submission).

Since my urls.py is like:

url(r'^checkout/$', 'checkout', {'SSL': settings.ENABLE_SSL }, name = 'checkout'),

and my view is similar to:

def checkout(request):
    if cart.empty(request):
        cart = urlresolvers.reverse('shopping_cart')
        return HttpResponseRedirect(cart)
    if request.method == 'POST':
        checkoutform = CheckoutFormPreview(CheckoutForm)

This last line is where I would like to name it, but I canโ€™t figure out how to wrap it ... Suggestions?

+3
source
1

, CheckoutFormPreview(CheckoutForm) , url. , request. .

, (untested):

if request.method == 'POST':
    form_preview_view = CheckoutFormPreview(CheckoutForm)
    return form_preview_view(request)
+2

All Articles