Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

context_processors.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from itertools import chain
  2. from django.core.exceptions import ObjectDoesNotExist
  3. from oscar.apps.promotions.abstract_models import BANNER, LEFT_POD, RIGHT_POD
  4. from oscar.core.loading import import_module
  5. import_module('promotions.models', ['PagePromotion', 'KeywordPromotion',
  6. 'PageMerchandisingBlock', 'KeywordMerchandisingBlock'], locals())
  7. def promotions(request):
  8. u"""
  9. For adding bindings for banners and pods to the template
  10. context.
  11. """
  12. bindings = {
  13. 'url_path': request.path
  14. }
  15. promotions = PagePromotion._default_manager.select_related().filter(page_url=request.path)
  16. if 'q' in request.GET:
  17. keyword_promotions = KeywordPromotion._default_manager.select_related().filter(keyword=request.GET['q'])
  18. if keyword_promotions.count() > 0:
  19. promotions = list(chain(promotions, keyword_promotions))
  20. bindings['banners'], bindings['left_pods'], bindings['right_pods'] = _split_by_position(promotions)
  21. return bindings
  22. def merchandising_blocks(request):
  23. bindings = {
  24. 'url_path': request.path
  25. }
  26. blocks = PageMerchandisingBlock._default_manager.select_related().filter(page_url=request.path)
  27. if 'q' in request.GET:
  28. keyword_blocks = KeywordMerchandisingBlock._default_manager.select_related().filter(keyword=request.GET['q'])
  29. if keyword_blocks.count() > 0:
  30. blocks = list(chain(blocks, keyword_blocks))
  31. bindings['merchandising_blocks'] = blocks
  32. return bindings
  33. def _split_by_position(linked_promotions):
  34. # We split the queries into 3 sets based on the position field
  35. banners, left_pods, right_pods = [], [], []
  36. for linked_promotion in linked_promotions:
  37. promotion = linked_promotion.promotion
  38. if linked_promotion.position == BANNER:
  39. banners.append(promotion)
  40. elif linked_promotion.position == LEFT_POD:
  41. left_pods.append(promotion)
  42. elif linked_promotion.position == RIGHT_POD:
  43. right_pods.append(promotion)
  44. promotion.set_proxy_link(linked_promotion.get_link())
  45. return banners, left_pods, right_pods