Merge pull request '35/order-confirmation-page' (#41) from 35/order-confirmation-page into master
Reviewed-on: #41
This commit is contained in:
commit
51851910c6
|
@ -21,6 +21,7 @@ def order_product(product, timeframe, formdata):
|
||||||
resource = get_object_or_404(Resource, slug=res)
|
resource = get_object_or_404(Resource, slug=res)
|
||||||
ro = ResourceOrder.objects.create(value=value, resource=resource)
|
ro = ResourceOrder.objects.create(value=value, resource=resource)
|
||||||
po.resources.add(ro)
|
po.resources.add(ro)
|
||||||
|
return po
|
||||||
|
|
||||||
# Ordering without a timeframe
|
# Ordering without a timeframe
|
||||||
# if not timeframe:
|
# if not timeframe:
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<h2>Order Confirmation</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Thank you for the order. The details are below:
|
||||||
|
</p>
|
||||||
|
<div class="order-details">
|
||||||
|
Order ID: {{ product_order.id }}<br/>
|
||||||
|
Product: {{ product_order.product.name }}
|
||||||
|
</div>
|
||||||
|
<br/>
|
||||||
|
<div>
|
||||||
|
<a href="{% url 'index' %}">Go back to the home page</a>
|
||||||
|
</div>
|
|
@ -10,12 +10,23 @@ from .models import *
|
||||||
from .forms import *
|
from .forms import *
|
||||||
from .services 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):
|
class ProductOneTimeOrderView(FormView):
|
||||||
form_class = ProductOneTimeOrderForm
|
form_class = ProductOneTimeOrderForm
|
||||||
template_name = 'app/productorder_form.html'
|
template_name = 'app/productorder_form.html'
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return "/"
|
return reverse("order-confirmation")
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
kwargs = super().get_form_kwargs()
|
kwargs = super().get_form_kwargs()
|
||||||
|
@ -58,8 +69,8 @@ class ProductOneTimeOrderView(FormView):
|
||||||
else:
|
else:
|
||||||
timeframe = None
|
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)
|
return super().form_valid(form)
|
||||||
|
|
||||||
class ProductOrderView(ProductOneTimeOrderView):
|
class ProductOrderView(ProductOneTimeOrderView):
|
||||||
|
|
|
@ -23,6 +23,7 @@ urlpatterns = [
|
||||||
path('order/<slug:product>/', appviews.ProductOrderView.as_view(), name='product-order'),
|
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/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/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/', appviews.ProductListView.as_view(), name='products'),
|
||||||
path('product/<slug:slug>/', appviews.ProductDetailView.as_view(), name='product-detail'),
|
path('product/<slug:slug>/', appviews.ProductDetailView.as_view(), name='product-detail'),
|
||||||
path('', appviews.IndexView.as_view(), name='index'),
|
path('', appviews.IndexView.as_view(), name='index'),
|
||||||
|
|
Loading…
Reference in New Issue