Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Apply all decorators on view level

Artur Smęt99131ce3ab7f
diff --git a/saleor/checkout/urls.py b/saleor/checkout/urls.py
index 627607277b..87af3473f3 100644
--- a/saleor/checkout/urls.py
+++ b/saleor/checkout/urls.py
@@ -1,10 +1,7 @@
from django.conf.urls import url
-from django.views.decorators.http import require_POST
from . import views
-remove_voucher_view = require_POST(views.discount.remove_voucher_view)
-
urlpatterns = [
url(r'^$', views.index_view, name='index'),
@@ -13,6 +10,7 @@ urlpatterns = [
url(r'^shipping-method/', views.shipping_method_view,
name='shipping-method'),
url(r'^summary/', views.summary_view, name='summary'),
- url(r'^remove_voucher/', remove_voucher_view, name='remove-voucher'),
+ url(r'^remove_voucher/', views.discount.remove_voucher_view,
+ name='remove-voucher'),
url(r'^login/', views.login, name='login'),
]
diff --git a/saleor/checkout/views/discount.py b/saleor/checkout/views/discount.py
index d9e25540ed..2646350265 100644
--- a/saleor/checkout/views/discount.py
+++ b/saleor/checkout/views/discount.py
@@ -4,7 +4,9 @@ from django.contrib import messages
from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.utils.translation import pgettext
+from django.views.decorators.http import require_POST
+from ..core import load_checkout
from ...discount.forms import CheckoutDiscountForm
from ...discount.models import Voucher
@@ -56,6 +58,8 @@ def validate_voucher(view):
return func
+@require_POST
+@load_checkout
def remove_voucher_view(request, checkout, cart):
next_url = request.GET.get('next', request.META['HTTP_REFERER'])
del checkout.discount