Skip to content

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

Refactor index view

Marcin Gębalad34f36852f37
diff --git a/saleor/dashboard/urls.py b/saleor/dashboard/urls.py
index 796c8babb5..68b3bbf579 100644
--- a/saleor/dashboard/urls.py
+++ b/saleor/dashboard/urls.py
@@ -7,10 +7,11 @@ from .payments.urls import urlpatterns as payments_urls
from .customer.urls import urlpatterns as customer_urls
-urlpatterns = patterns('',
- url(r'^$', core_views.IndexView.as_view(), name='index'),
- url(r'^orders/', include(order_urls)),
- url(r'^products/', include(product_urls)),
- url(r'^payments/', include(payments_urls)),
- url(r'^customers/', include(customer_urls)),
+urlpatterns = patterns(
+ '',
+ url(r'^$', core_views.index, name='index'),
+ url(r'^orders/', include(order_urls)),
+ url(r'^products/', include(product_urls)),
+ url(r'^payments/', include(payments_urls)),
+ url(r'^customers/', include(customer_urls)),
)
diff --git a/saleor/dashboard/views.py b/saleor/dashboard/views.py
index ecc217d827..5ccb0148f0 100644
--- a/saleor/dashboard/views.py
+++ b/saleor/dashboard/views.py
@@ -51,20 +51,11 @@ class FilterByStatusMixin(object):
return filters
-class IndexView(StaffMemberOnlyMixin, TemplateView):
- template_name = 'dashboard/index.html'
-
- def get_context_data(self, **kwargs):
- ctx = super(IndexView, self).get_context_data(**kwargs)
- ctx['preauthorized_payments'] = self.get_preauthorized_payments()
- ctx['orders_to_ship'] = self.get_orders_to_ship()
- return ctx
-
- def get_preauthorized_payments(self):
- payments = Payment.objects.filter(status='preauth').order_by('-created')
- for payment in payments:
- payment.total = Price(payment.total, currency=payment.currency)
- return payments
-
- def get_orders_to_ship(self):
- return Order.objects.filter(status='fully-paid')
+@staff_member_required
+def index(request):
+ orders_to_ship = Order.objects.filter(status='fully-paid')
+ payments = Payment.objects.filter(status='preauth').order_by('-created')
+ for payment in payments:
+ payment.total = Price(payment.total, currency=payment.currency)
+ ctx = {'preauthorized_payments': payments, 'orders_to_ship': orders_to_ship}
+ return TemplateResponse(request, 'dashboard/index.html', ctx)