forked from CGM_Public/pretix_original
Do not attach empty files for orders without tickets
This commit is contained in:
@@ -686,6 +686,15 @@ class Order(LockModel, LoggedModel):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def positions_with_tickets(self):
|
||||||
|
for op in self.positions.all():
|
||||||
|
if op.addon_to_id and not self.event.settings.ticket_download_addons:
|
||||||
|
continue
|
||||||
|
if not op.item.admission and not self.event.settings.ticket_download_nonadm:
|
||||||
|
continue
|
||||||
|
yield op
|
||||||
|
|
||||||
|
|
||||||
def answerfile_name(instance, filename: str) -> str:
|
def answerfile_name(instance, filename: str) -> str:
|
||||||
secret = get_random_string(length=32, allowed_chars=string.ascii_letters + string.digits)
|
secret = get_random_string(length=32, allowed_chars=string.ascii_letters + string.digits)
|
||||||
|
|||||||
@@ -117,6 +117,8 @@ def get_tickets_for_order(order):
|
|||||||
|
|
||||||
if p.multi_download_enabled:
|
if p.multi_download_enabled:
|
||||||
try:
|
try:
|
||||||
|
if len(order.positions_with_tickets) == 0:
|
||||||
|
continue
|
||||||
ct = CachedCombinedTicket.objects.filter(
|
ct = CachedCombinedTicket.objects.filter(
|
||||||
order=order, provider=p.identifier, file__isnull=False
|
order=order, provider=p.identifier, file__isnull=False
|
||||||
).last()
|
).last()
|
||||||
@@ -132,11 +134,7 @@ def get_tickets_for_order(order):
|
|||||||
except:
|
except:
|
||||||
logger.exception('Failed to generate ticket.')
|
logger.exception('Failed to generate ticket.')
|
||||||
else:
|
else:
|
||||||
for pos in order.positions.all():
|
for pos in order.positions_with_tickets:
|
||||||
if pos.addon_to and not order.event.settings.ticket_download_addons:
|
|
||||||
continue
|
|
||||||
if not pos.item.admission and not order.event.settings.ticket_download_nonadm:
|
|
||||||
continue
|
|
||||||
try:
|
try:
|
||||||
ct = CachedTicket.objects.filter(
|
ct = CachedTicket.objects.filter(
|
||||||
order_position=pos, provider=p.identifier, file__isnull=False
|
order_position=pos, provider=p.identifier, file__isnull=False
|
||||||
|
|||||||
@@ -70,14 +70,12 @@ class BaseTicketOutput:
|
|||||||
If you override this method, make sure that positions that are addons (i.e. ``addon_to``
|
If you override this method, make sure that positions that are addons (i.e. ``addon_to``
|
||||||
is set) are only outputted if the event setting ``ticket_download_addons`` is active.
|
is set) are only outputted if the event setting ``ticket_download_addons`` is active.
|
||||||
Do the same for positions that are non-admission without ``ticket_download_nonadm`` active.
|
Do the same for positions that are non-admission without ``ticket_download_nonadm`` active.
|
||||||
|
If you want, you can just iterate over ``order.positions_with_tickets`` which applies the
|
||||||
|
appropriate filters for you.
|
||||||
"""
|
"""
|
||||||
with tempfile.TemporaryDirectory() as d:
|
with tempfile.TemporaryDirectory() as d:
|
||||||
with ZipFile(os.path.join(d, 'tmp.zip'), 'w') as zipf:
|
with ZipFile(os.path.join(d, 'tmp.zip'), 'w') as zipf:
|
||||||
for pos in order.positions.all():
|
for pos in order.positions_with_tickets:
|
||||||
if pos.addon_to_id and not self.event.settings.ticket_download_addons:
|
|
||||||
continue
|
|
||||||
if not pos.item.admission and not self.event.settings.ticket_download_nonadm:
|
|
||||||
continue
|
|
||||||
fname, __, content = self.generate(pos)
|
fname, __, content = self.generate(pos)
|
||||||
zipf.writestr('{}-{}{}'.format(
|
zipf.writestr('{}-{}{}'.format(
|
||||||
order.code, pos.positionid, os.path.splitext(fname)[1]
|
order.code, pos.positionid, os.path.splitext(fname)[1]
|
||||||
|
|||||||
@@ -73,12 +73,7 @@ class PdfTicketOutput(BaseTicketOutput):
|
|||||||
def generate_order(self, order: Order):
|
def generate_order(self, order: Order):
|
||||||
merger = PdfFileMerger()
|
merger = PdfFileMerger()
|
||||||
with language(order.locale):
|
with language(order.locale):
|
||||||
for op in order.positions.all():
|
for op in order.positions_with_tickets:
|
||||||
if op.addon_to_id and not self.event.settings.ticket_download_addons:
|
|
||||||
continue
|
|
||||||
if not op.item.admission and not self.event.settings.ticket_download_nonadm:
|
|
||||||
continue
|
|
||||||
|
|
||||||
layout = self.layout_map.get(
|
layout = self.layout_map.get(
|
||||||
(op.item_id, order.sales_channel),
|
(op.item_id, order.sales_channel),
|
||||||
self.layout_map.get(
|
self.layout_map.get(
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class OrderDetails(EventViewMixin, OrderDetailMixin, CartMixin, TemplateView):
|
|||||||
can_download = all([r for rr, r in allow_ticket_download.send(self.request.event, order=self.order)])
|
can_download = all([r for rr, r in allow_ticket_download.send(self.request.event, order=self.order)])
|
||||||
if self.request.event.settings.ticket_download_date:
|
if self.request.event.settings.ticket_download_date:
|
||||||
ctx['ticket_download_date'] = self.order.ticket_download_date
|
ctx['ticket_download_date'] = self.order.ticket_download_date
|
||||||
ctx['can_download'] = can_download and self.order.ticket_download_available
|
ctx['can_download'] = can_download and self.order.ticket_download_available and self.order.positions_with_tickets
|
||||||
ctx['download_buttons'] = self.download_buttons
|
ctx['download_buttons'] = self.download_buttons
|
||||||
ctx['cart'] = self.get_cart(
|
ctx['cart'] = self.get_cart(
|
||||||
answers=True, downloads=ctx['can_download'],
|
answers=True, downloads=ctx['can_download'],
|
||||||
|
|||||||
Reference in New Issue
Block a user