瀏覽代碼

Fix bug with history helper templatetag

Symptom:
Adding to basket did not work

Cause:
Was not passing the request variable as part of the context and so the
basket form could not be generated.  Hence adding to basket led to an
error.

Solution:
Add request to the context returned by the helper function.
master
David Winterbottom 13 年之前
父節點
當前提交
6f2401b1a3

+ 3
- 1
oscar/templates/oscar/catalogue/detail.html 查看文件

@@ -207,7 +207,9 @@
207 207
             </div>
208 208
         </div>
209 209
         {% endif %}
210
-    {% recently_viewed_products %}
210
+
211
+		{% recently_viewed_products %}
212
+
211 213
     </div>
212 214
 </article><!-- End of product page -->
213 215
 {% endblock content %}

+ 0
- 1
oscar/templates/oscar/customer/history/recently_viewed_products.html 查看文件

@@ -14,5 +14,4 @@
14 14
         </ul>
15 15
     </div>
16 16
 </div>
17
-<!-- End Elastislide Carousel -->
18 17
 {% endif %}

+ 7
- 8
oscar/templatetags/history_tags.py 查看文件

@@ -2,6 +2,7 @@ from django import template
2 2
 from django.db.models import get_model
3 3
 
4 4
 from oscar.core.loading import get_class
5
+
5 6
 Product = get_model('catalogue', 'Product')
6 7
 get_recently_viewed_product_ids = get_class('customer.history_helpers',
7 8
                                             'get_recently_viewed_product_ids')
@@ -12,21 +13,19 @@ register = template.Library()
12 13
 @register.inclusion_tag('customer/history/recently_viewed_products.html',
13 14
                         takes_context=True)
14 15
 def recently_viewed_products(context):
15
-    u"""
16
+    """
16 17
     Inclusion tag listing the most recently viewed products
17 18
     """
18 19
     request = context['request']
19 20
     product_ids = get_recently_viewed_product_ids(request)
20 21
 
21
-    try:
22
-        current_product = context.get('product', None)
22
+    current_product = context.get('product', None)
23
+    if current_product.id in product_ids:
23 24
         product_ids.remove(current_product.id)
24
-    except (ValueError, AttributeError):
25
-        pass
26
-
27
-    product_dict = Product.browsable.in_bulk(product_ids)
28 25
 
29 26
     # Reordering as the id order gets messed up in the query
27
+    product_dict = Product.browsable.in_bulk(product_ids)
30 28
     product_ids.reverse()
31 29
     products = [product_dict[id] for id in product_ids if id in product_dict]
32
-    return {'products': products}
30
+    return {'products': products,
31
+            'request': request}

Loading…
取消
儲存