Ver código fonte

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 anos atrás
pai
commit
6f2401b1a3

+ 3
- 1
oscar/templates/oscar/catalogue/detail.html Ver arquivo

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

+ 0
- 1
oscar/templates/oscar/customer/history/recently_viewed_products.html Ver arquivo

14
         </ul>
14
         </ul>
15
     </div>
15
     </div>
16
 </div>
16
 </div>
17
-<!-- End Elastislide Carousel -->
18
 {% endif %}
17
 {% endif %}

+ 7
- 8
oscar/templatetags/history_tags.py Ver arquivo

2
 from django.db.models import get_model
2
 from django.db.models import get_model
3
 
3
 
4
 from oscar.core.loading import get_class
4
 from oscar.core.loading import get_class
5
+
5
 Product = get_model('catalogue', 'Product')
6
 Product = get_model('catalogue', 'Product')
6
 get_recently_viewed_product_ids = get_class('customer.history_helpers',
7
 get_recently_viewed_product_ids = get_class('customer.history_helpers',
7
                                             'get_recently_viewed_product_ids')
8
                                             'get_recently_viewed_product_ids')
12
 @register.inclusion_tag('customer/history/recently_viewed_products.html',
13
 @register.inclusion_tag('customer/history/recently_viewed_products.html',
13
                         takes_context=True)
14
                         takes_context=True)
14
 def recently_viewed_products(context):
15
 def recently_viewed_products(context):
15
-    u"""
16
+    """
16
     Inclusion tag listing the most recently viewed products
17
     Inclusion tag listing the most recently viewed products
17
     """
18
     """
18
     request = context['request']
19
     request = context['request']
19
     product_ids = get_recently_viewed_product_ids(request)
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
         product_ids.remove(current_product.id)
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
     # Reordering as the id order gets messed up in the query
26
     # Reordering as the id order gets messed up in the query
27
+    product_dict = Product.browsable.in_bulk(product_ids)
30
     product_ids.reverse()
28
     product_ids.reverse()
31
     products = [product_dict[id] for id in product_ids if id in product_dict]
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}

Carregando…
Cancelar
Salvar