Re-added the ability to restrict a product sale by time

This commit is contained in:
Raphael Michel
2015-12-06 18:18:54 +01:00
parent 4a1122a862
commit e70485e7fb
9 changed files with 149 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
import sys
from django.db.models import Count
from django.db.models import Q, Count
from django.utils.timezone import now
from django.views.generic import TemplateView
from pretix.presale.views import CartMixin, EventViewMixin
@@ -13,7 +14,9 @@ class EventIndex(EventViewMixin, CartMixin, TemplateView):
context = super().get_context_data(**kwargs)
# Fetch all items
items = self.request.event.items.all().filter(
active=True
Q(active=True)
& Q(Q(available_from__isnull=True) | Q(available_from__lte=now()))
& Q(Q(available_until__isnull=True) | Q(available_until__gte=now()))
).select_related(
'category', # for re-grouping
).prefetch_related(