Clarify show_vouchers constraint with subevents

This commit is contained in:
Raphael Michel
2019-12-12 11:56:36 +01:00
parent 7d6b3e7140
commit 8a17fedaa6
2 changed files with 11 additions and 7 deletions

View File

@@ -252,7 +252,7 @@
<div class="col-md-3 col-xs-6 col-md-offset-3 price">
<strong>{{ cart.total|money:event.currency }}</strong>
{% if editable and show_vouchers and not cart.all_with_voucher %}
{% if editable and vouchers_exist and not cart.all_with_voucher %}
<br>
<a class="js-only apply-voucher-toggle" href="#">
<span class="fa fa-tag"></span> {% trans "Redeem a voucher" %}
@@ -273,4 +273,4 @@
{% endif %}
</div>
<div class="clearfix"></div>
</div>
</div>

View File

@@ -306,6 +306,13 @@ class EventIndex(EventViewMixin, EventListMixin, CartMixin, TemplateView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# Show voucher option if an event is selected and vouchers exist
vouchers_exist = self.request.event.cache.get('vouchers_exist')
if vouchers_exist is None:
vouchers_exist = self.request.event.vouchers.exists()
self.request.event.cache.set('vouchers_exist', vouchers_exist)
if not self.request.event.has_subevents or self.subevent:
# Fetch all items
items, display_add_to_cart = get_grouped_items(self.request.event, self.subevent,
@@ -316,14 +323,11 @@ class EventIndex(EventViewMixin, EventListMixin, CartMixin, TemplateView):
context['items_by_category'] = item_group_by_category(items)
context['display_add_to_cart'] = display_add_to_cart
# Show voucher option if an event is selected and vouchers exist
vouchers_exist = self.request.event.cache.get('vouchers_exist')
if vouchers_exist is None:
vouchers_exist = self.request.event.vouchers.exists()
self.request.event.cache.set('vouchers_exist', vouchers_exist)
context['show_vouchers'] = vouchers_exist
context['vouchers_exist'] = vouchers_exist
else:
context['show_vouchers'] = False
context['vouchers_exist'] = vouchers_exist
context['ev'] = self.subevent or self.request.event
context['subevent'] = self.subevent