|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
+import json
|
|
|
2
|
+
|
|
1
|
3
|
from django.dispatch import receiver
|
|
2
|
4
|
from django.conf import settings
|
|
3
|
5
|
|
|
4
|
6
|
from oscar.services import import_module
|
|
5
|
|
-
|
|
6
|
|
-import json
|
|
7
|
|
-
|
|
8
|
7
|
product_signals = import_module('product.signals', ['product_viewed'])
|
|
9
|
|
-max_products = settings.OSCAR_RECENTLY_VIEWED_PRODUCTS
|
|
|
8
|
+
|
|
|
9
|
+MAX_PRODUCTS = getattr(settings, 'OSCAR_RECENTLY_VIEWED_PRODUCTS', 5)
|
|
10
|
10
|
|
|
11
|
11
|
# Helpers
|
|
12
|
12
|
|
|
13
|
13
|
def get_recently_viewed_product_ids(request):
|
|
14
|
14
|
u"""
|
|
15
|
|
- The list of ids of the last products browsed by the user
|
|
|
15
|
+ Returns the list of ids of the last products browsed by the user
|
|
16
|
16
|
|
|
17
|
17
|
Limited to the max number defined in settings.py
|
|
18
|
18
|
under OSCAR_RECENTLY_VIEWED_PRODUCTS.
|
|
|
@@ -22,7 +22,7 @@ def get_recently_viewed_product_ids(request):
|
|
22
|
22
|
try:
|
|
23
|
23
|
product_ids = _get_list_from_json_string(request.COOKIES['oscar_recently_viewed_products'])
|
|
24
|
24
|
except ValueError:
|
|
25
|
|
- # This can occure if something messes up the cookie
|
|
|
25
|
+ # This can occur if something messes up the cookie
|
|
26
|
26
|
pass
|
|
27
|
27
|
return product_ids
|
|
28
|
28
|
|
|
|
@@ -35,11 +35,9 @@ def _update_recently_viewed_products(product, request, response):
|
|
35
|
35
|
if product.id in product_ids:
|
|
36
|
36
|
product_ids.remove(product.id)
|
|
37
|
37
|
product_ids.append(product.id)
|
|
38
|
|
- if (len(product_ids) > max_products):
|
|
39
|
|
- assert False
|
|
40
|
|
- del product_ids[max_products:]
|
|
|
38
|
+ if (len(product_ids) > MAX_PRODUCTS):
|
|
|
39
|
+ del product_ids[MAX_PRODUCTS:]
|
|
41
|
40
|
response.set_cookie('oscar_recently_viewed_products', _get_json_string_from_list(product_ids))
|
|
42
|
|
- return
|
|
43
|
41
|
|
|
44
|
42
|
def _get_list_from_json_string(cookie_value):
|
|
45
|
43
|
u""" Simple function to convert lists to json """
|