Add order-confirmation view and take user to this after the purchase
This commit is contained in:
parent
72f47dec7c
commit
c50d688171
|
@ -10,12 +10,23 @@ from .models import *
|
|||
from .forms import *
|
||||
from .services import *
|
||||
|
||||
|
||||
class OrderConfirmationView(TemplateView):
|
||||
template_name = 'app/order_confirmation.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
po_id = self.request.session.pop('product_order_id', None)
|
||||
context['product_order'] = get_object_or_404(ProductOrder, id=po_id)
|
||||
return context
|
||||
|
||||
|
||||
class ProductOneTimeOrderView(FormView):
|
||||
form_class = ProductOneTimeOrderForm
|
||||
template_name = 'app/productorder_form.html'
|
||||
|
||||
def get_success_url(self):
|
||||
return "/"
|
||||
return reverse("order-confirmation")
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
|
@ -58,8 +69,8 @@ class ProductOneTimeOrderView(FormView):
|
|||
else:
|
||||
timeframe = None
|
||||
|
||||
order_product(product, timeframe, form.cleaned_data)
|
||||
|
||||
po = order_product(product, timeframe, form.cleaned_data)
|
||||
self.request.session['product_order_id'] = po.id
|
||||
return super().form_valid(form)
|
||||
|
||||
class ProductOrderView(ProductOneTimeOrderView):
|
||||
|
|
|
@ -23,6 +23,7 @@ urlpatterns = [
|
|||
path('order/<slug:product>/', appviews.ProductOrderView.as_view(), name='product-order'),
|
||||
path('order/recurring/<slug:product>/<slug:timeframe>/', appviews.ProductOrderView.as_view(), name='product-order-tf'),
|
||||
path('order/onetime/<slug:product>/', appviews.ProductOneTimeOrderView.as_view(), name='product-order-onetime'),
|
||||
path('order-confirmation', appviews.OrderConfirmationView.as_view(), name='order-confirmation'),
|
||||
path('product/', appviews.ProductListView.as_view(), name='products'),
|
||||
path('product/<slug:slug>/', appviews.ProductDetailView.as_view(), name='product-detail'),
|
||||
path('', appviews.IndexView.as_view(), name='index'),
|
||||
|
|
Loading…
Reference in New Issue