|
|
@@ -9,11 +9,14 @@ from django.template.response import TemplateResponse
|
|
9
|
9
|
|
|
10
|
10
|
from oscar.core.loading import import_module
|
|
11
|
11
|
|
|
12
|
|
-product_models = import_module('product.models', ['Item', 'ItemClass'])
|
|
13
|
12
|
product_signals = import_module('product.signals', ['product_viewed', 'product_search'])
|
|
14
|
13
|
basket_forms = import_module('basket.forms', ['FormFactory'])
|
|
15
|
14
|
history_helpers = import_module('customer.history_helpers', ['receive_product_view'])
|
|
16
|
15
|
|
|
|
16
|
+from django.db.models import get_model
|
|
|
17
|
+
|
|
|
18
|
+item_model = get_model('product','item')
|
|
|
19
|
+item_class_model = get_model('product', 'itemclass')
|
|
17
|
20
|
|
|
18
|
21
|
class ItemDetailView(DetailView):
|
|
19
|
22
|
u"""View a single product."""
|
|
|
@@ -41,7 +44,7 @@ class ItemDetailView(DetailView):
|
|
41
|
44
|
|
|
42
|
45
|
We cache the object as this method gets called twice."""
|
|
43
|
46
|
if not self._item:
|
|
44
|
|
- self._item = get_object_or_404(product_models.Item, pk=self.kwargs['item_id'])
|
|
|
47
|
+ self._item = get_object_or_404(item_model, pk=self.kwargs['item_id'])
|
|
45
|
48
|
return self._item
|
|
46
|
49
|
|
|
47
|
50
|
def get_context_data(self, **kwargs):
|
|
|
@@ -60,8 +63,8 @@ class ItemClassListView(ListView):
|
|
60
|
63
|
paginate_by = 20
|
|
61
|
64
|
|
|
62
|
65
|
def get_queryset(self):
|
|
63
|
|
- item_class = get_object_or_404(product_models.ItemClass, slug=self.kwargs['item_class_slug'])
|
|
64
|
|
- return product_models.Item.browsable.filter(item_class=item_class)
|
|
|
66
|
+ item_class = get_object_or_404(item_class_model, slug=self.kwargs['item_class_slug'])
|
|
|
67
|
+ return item_model.browsable.filter(item_class=item_class)
|
|
65
|
68
|
|
|
66
|
69
|
|
|
67
|
70
|
class ProductListView(ListView):
|
|
|
@@ -84,9 +87,9 @@ class ProductListView(ListView):
|
|
84
|
87
|
# Send signal to record the view of this product
|
|
85
|
88
|
product_signals.product_search.send(sender=self, query=q, user=self.request.user)
|
|
86
|
89
|
|
|
87
|
|
- return product_models.Item.browsable.filter(title__icontains=q)
|
|
|
90
|
+ return item_model.browsable.filter(title__icontains=q)
|
|
88
|
91
|
else:
|
|
89
|
|
- return product_models.Item.browsable.all()
|
|
|
92
|
+ return item_model.browsable.all()
|
|
90
|
93
|
|
|
91
|
94
|
def get_context_data(self, **kwargs):
|
|
92
|
95
|
context = super(ProductListView, self).get_context_data(**kwargs)
|