respect individual allowed positions from plugins

This commit is contained in:
Mira Weller
2024-01-25 17:38:18 +01:00
parent 3330c6fcd6
commit f7b4e37c95
8 changed files with 37 additions and 33 deletions

View File

@@ -1137,12 +1137,20 @@ class Order(LockModel, LoggedModel):
attach_tickets=True,
)
@property
def positions_with_tickets_ignoring_plugins(self):
return (op for op in self.positions.select_related('item') if op.generate_ticket)
@property
def positions_with_tickets(self):
for op in self.positions.select_related('item'):
if not op.generate_ticket:
continue
yield op
signal_response = allow_ticket_download.send(self.event, order=self)
print("signal_response", signal_response)
if all([r is True for rr, r in signal_response]):
return self.positions_with_tickets_ignoring_plugins
elif any([r is False for rr, r in signal_response]):
return []
else:
return set.intersection(set(self.positions_with_tickets_ignoring_plugins), *[set(r) for rr, r in signal_response if isinstance(r, Iterable)])
def create_transactions(self, is_new=False, positions=None, fees=None, dt_now=None, migrated=False,
_backfill_before_cancellation=False, save=True):
@@ -1200,15 +1208,6 @@ class Order(LockModel, LoggedModel):
_transactions_mark_order_clean(self.pk)
return create
@property
def plugins_allow_ticket_download(self):
signal_response = allow_ticket_download.send(self.event, order=self)
if all([r == True for rr, r in signal_response]):
return True
elif any([r == False for rr, r in signal_response]):
return False
else:
return set.intersection(*[set(r) for rr, r in signal_response if isinstance(r, Iterable)])
def answerfile_name(instance, filename: str) -> str:

View File

@@ -1408,20 +1408,17 @@ def send_download_reminders(sender, **kwargs):
if o.download_reminder_sent:
# Race condition
continue
if not o.plugins_allow_ticket_download:
positions = o.positions_with_tickets
if not positions:
continue
if not o.ticket_download_available:
continue
positions = o.positions.select_related('item')
if o.status != Order.STATUS_PAID:
if o.status != Order.STATUS_PENDING or o.require_approval or (not o.valid_if_pending and not o.event.settings.ticket_download_pending):
continue
if not any(p.generate_ticket for p in positions):
continue
with language(o.locale, o.event.settings.region):
o.download_reminder_sent = True
o.save(update_fields=['download_reminder_sent'])

View File

@@ -21,6 +21,7 @@
#
import logging
import os
from typing import Iterable
from django.core.files.base import ContentFile
from django.utils.timezone import now
@@ -124,8 +125,8 @@ def preview(event: int, provider: str):
def get_tickets_for_order(order, base_position=None):
can_download = order.plugins_allow_ticket_download
if not can_download:
positions_with_ticket = order.positions_with_tickets
if not positions_with_ticket:
return []
if not order.ticket_download_available:
return []
@@ -138,7 +139,7 @@ def get_tickets_for_order(order, base_position=None):
tickets = []
positions = list(order.positions_with_tickets)
positions = list(positions_with_ticket)
if base_position:
# Only the given position and its children
positions = [

View File

@@ -96,6 +96,9 @@ class BaseTicketOutput:
"""
raise NotImplementedError()
def get_tickets_to_print(self, order):
return order.positions_with_tickets
def generate_order(self, order: Order) -> Tuple[str, str, str]:
"""
This method is the same as order() but should not generate one file per order position
@@ -116,7 +119,7 @@ class BaseTicketOutput:
"""
with tempfile.TemporaryDirectory() as d:
with ZipFile(os.path.join(d, 'tmp.zip'), 'w') as zipf:
for pos in order.positions_with_tickets:
for pos in self.get_tickets_to_print(order):
fname, __, content = self.generate(pos)
zipf.writestr('{}-{}{}'.format(
order.code, pos.positionid, os.path.splitext(fname)[1]