|
|
@@ -9,7 +9,8 @@ from django.utils.translation import gettext_lazy as _
|
|
9
|
9
|
from django.views import generic
|
|
10
|
10
|
from django_tables2 import SingleTableMixin, SingleTableView
|
|
11
|
11
|
|
|
12
|
|
-from oscar.core.loading import get_classes, get_model
|
|
|
12
|
+from oscar.core.decorators import deprecated
|
|
|
13
|
+from oscar.core.loading import get_class, get_classes, get_model
|
|
13
|
14
|
from oscar.views.generic import ObjectLookupView
|
|
14
|
15
|
|
|
15
|
16
|
(ProductForm,
|
|
|
@@ -53,6 +54,7 @@ ProductTable, CategoryTable, AttributeOptionGroupTable, OptionTable \
|
|
53
|
54
|
('PopUpWindowCreateMixin',
|
|
54
|
55
|
'PopUpWindowUpdateMixin',
|
|
55
|
56
|
'PopUpWindowDeleteMixin'))
|
|
|
57
|
+PartnerProductFilterMixin = get_class('dashboard.catalogue.mixins', 'PartnerProductFilterMixin')
|
|
56
|
58
|
Product = get_model('catalogue', 'Product')
|
|
57
|
59
|
Category = get_model('catalogue', 'Category')
|
|
58
|
60
|
ProductImage = get_model('catalogue', 'ProductImage')
|
|
|
@@ -65,6 +67,7 @@ AttributeOptionGroup = get_model('catalogue', 'AttributeOptionGroup')
|
|
65
|
67
|
Option = get_model('catalogue', 'Option')
|
|
66
|
68
|
|
|
67
|
69
|
|
|
|
70
|
+@deprecated
|
|
68
|
71
|
def filter_products(queryset, user):
|
|
69
|
72
|
"""
|
|
70
|
73
|
Restrict the queryset to products the given user has access to.
|
|
|
@@ -78,7 +81,7 @@ def filter_products(queryset, user):
|
|
78
|
81
|
return queryset.filter(stockrecords__partner__users__pk=user.pk).distinct()
|
|
79
|
82
|
|
|
80
|
83
|
|
|
81
|
|
-class ProductListView(SingleTableView):
|
|
|
84
|
+class ProductListView(PartnerProductFilterMixin, SingleTableView):
|
|
82
|
85
|
|
|
83
|
86
|
"""
|
|
84
|
87
|
Dashboard view of the product list.
|
|
|
@@ -113,12 +116,6 @@ class ProductListView(SingleTableView):
|
|
113
|
116
|
def get_table_pagination(self, table):
|
|
114
|
117
|
return dict(per_page=settings.OSCAR_DASHBOARD_ITEMS_PER_PAGE)
|
|
115
|
118
|
|
|
116
|
|
- def filter_queryset(self, queryset):
|
|
117
|
|
- """
|
|
118
|
|
- Apply any filters to restrict the products that appear on the list
|
|
119
|
|
- """
|
|
120
|
|
- return filter_products(queryset, self.request.user)
|
|
121
|
|
-
|
|
122
|
119
|
def get_queryset(self):
|
|
123
|
120
|
"""
|
|
124
|
121
|
Build the queryset for this list
|
|
|
@@ -194,7 +191,7 @@ class ProductCreateRedirectView(generic.RedirectView):
|
|
194
|
191
|
return self.get_invalid_product_class_url()
|
|
195
|
192
|
|
|
196
|
193
|
|
|
197
|
|
-class ProductCreateUpdateView(generic.UpdateView):
|
|
|
194
|
+class ProductCreateUpdateView(PartnerProductFilterMixin, generic.UpdateView):
|
|
198
|
195
|
"""
|
|
199
|
196
|
Dashboard view that is can both create and update products of all kinds.
|
|
200
|
197
|
It can be used in three different ways, each of them with a unique URL
|
|
|
@@ -252,7 +249,7 @@ class ProductCreateUpdateView(generic.UpdateView):
|
|
252
|
249
|
"""
|
|
253
|
250
|
Filter products that the user doesn't have permission to update
|
|
254
|
251
|
"""
|
|
255
|
|
- return filter_products(Product.objects.all(), self.request.user)
|
|
|
252
|
+ return self.filter_queryset(Product.objects.all())
|
|
256
|
253
|
|
|
257
|
254
|
def get_object(self, queryset=None):
|
|
258
|
255
|
"""
|
|
|
@@ -451,7 +448,7 @@ class ProductCreateUpdateView(generic.UpdateView):
|
|
451
|
448
|
return self.get_url_with_querystring(url)
|
|
452
|
449
|
|
|
453
|
450
|
|
|
454
|
|
-class ProductDeleteView(generic.DeleteView):
|
|
|
451
|
+class ProductDeleteView(PartnerProductFilterMixin, generic.DeleteView):
|
|
455
|
452
|
"""
|
|
456
|
453
|
Dashboard view to delete a product. Has special logic for deleting the
|
|
457
|
454
|
last child product.
|
|
|
@@ -465,7 +462,7 @@ class ProductDeleteView(generic.DeleteView):
|
|
465
|
462
|
"""
|
|
466
|
463
|
Filter products that the user doesn't have permission to update
|
|
467
|
464
|
"""
|
|
468
|
|
- return filter_products(Product.objects.all(), self.request.user)
|
|
|
465
|
+ return self.filter_queryset(Product.objects.all())
|
|
469
|
466
|
|
|
470
|
467
|
def get_context_data(self, **kwargs):
|
|
471
|
468
|
ctx = super().get_context_data(**kwargs)
|