Доброго времени суток.
Я разрабатываю магазин на Django-Oscar. После многочисленных правок, пропал блок "recently viewed products". Продукты на странице доступны через
templatetag
:
@register.inclusion_tag('customer/history/recently_viewed_products.html',
takes_context=True)
def recently_viewed_products(context):
"""
Inclusion tag listing the most recently viewed products
"""
# import pdb; pdb.set_trace() # debug yskhlyan
request = context['request']
products = history.get(request)
return {'products': products,
'request': request}
history.get(request)
выглядит вот так:
def get(request):
"""
Return a list of recently viewed products
"""
ids = extract(request)
# Reordering as the ID order gets messed up in the query
product_dict = Product.browsable.in_bulk(ids)
ids.reverse()
return [product_dict[id] for id in ids if id in product_dict]
def extract(request, response=None):
"""
Extract the IDs of products in the history cookie
"""
ids = []
cookie_name = settings.OSCAR_RECENTLY_VIEWED_COOKIE_NAME
if cookie_name in request.COOKIES:
try:
ids = json.loads(request.COOKIES[cookie_name])
except ValueError:
# This can occur if something messes up the cookie
if response:
response.delete_cookie(cookie_name)
else:
# Badly written web crawlers send garbage in double quotes
if not isinstance(ids, list):
ids = []
return ids
Потом в
pdb
я посмотрел на
request.COOKIES
, и внем нет нужного ключа(
settings.OSCAR_RECENTLY_VIEWED_COOKIE_NAME = 'oscar_history'
)
В чем может быть проблема? Если нужно показать другие методы - пишите, добавлю в вопрос.
Буду очень благодарен за помощь.