mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
Improve error messages when changing seating plans
This commit is contained in:
@@ -1,26 +1,39 @@
|
|||||||
from django.db.models import Count
|
from django.db.models import Count, Q
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from pretix.base.i18n import LazyLocaleException
|
||||||
from pretix.base.models import CartPosition, Seat
|
from pretix.base.models import CartPosition, Seat
|
||||||
|
|
||||||
|
|
||||||
class SeatProtected(Exception):
|
class SeatProtected(LazyLocaleException):
|
||||||
pass
|
def __init__(self, *args):
|
||||||
|
msg = args[0]
|
||||||
|
msgargs = args[1] if len(args) > 1 else None
|
||||||
|
self.args = args
|
||||||
|
if msgargs:
|
||||||
|
msg = _(msg) % msgargs
|
||||||
|
else:
|
||||||
|
msg = _(msg)
|
||||||
|
super().__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
def validate_plan_change(event, subevent, plan):
|
def validate_plan_change(event, subevent, plan):
|
||||||
current_taken_seats = set(
|
current_taken_seats = set(
|
||||||
event.seats.select_related('product').annotate(
|
event.seats.select_related('product').annotate(
|
||||||
has_op=Count('orderposition')
|
has_op=Count('orderposition')
|
||||||
).annotate(has_v=Count('vouchers')).filter(subevent=subevent, has_op=True).values_list('seat_guid', flat=True)
|
).annotate(has_v=Count('vouchers')).filter(
|
||||||
|
subevent=subevent,
|
||||||
|
).filter(
|
||||||
|
Q(has_v=True) | Q(has_op=True)
|
||||||
|
).values_list('seat_guid', flat=True)
|
||||||
)
|
)
|
||||||
new_seats = {
|
new_seats = {
|
||||||
ss.guid for ss in plan.iter_all_seats()
|
ss.guid for ss in plan.iter_all_seats()
|
||||||
} if plan else set()
|
} if plan else set()
|
||||||
leftovers = list(current_taken_seats - new_seats)
|
leftovers = list(current_taken_seats - new_seats)
|
||||||
if leftovers:
|
if leftovers:
|
||||||
raise SeatProtected(_('You can not change the plan since seat "{}" is not present in the new plan and is '
|
raise SeatProtected(_('You can not change the plan since seat "%s" is not present in the new plan and is '
|
||||||
'already sold.').format(leftovers[0]))
|
'already sold.'), leftovers[0])
|
||||||
|
|
||||||
|
|
||||||
def generate_seats(event, subevent, plan, mapping):
|
def generate_seats(event, subevent, plan, mapping):
|
||||||
@@ -70,8 +83,11 @@ def generate_seats(event, subevent, plan, mapping):
|
|||||||
|
|
||||||
for s in current_seats.values():
|
for s in current_seats.values():
|
||||||
if s.has_op:
|
if s.has_op:
|
||||||
raise SeatProtected(_('You can not change the plan since seat "{}" is not present in the new plan and is '
|
raise SeatProtected(_('You can not change the plan since seat "%s" is not present in the new plan and is '
|
||||||
'already sold.').format(s.name))
|
'already sold.', s.name))
|
||||||
|
if s.has_v:
|
||||||
|
raise SeatProtected(_('You can not change the plan since seat "%s" is not present in the new plan and is '
|
||||||
|
'already used in a voucher.', s.name))
|
||||||
|
|
||||||
Seat.objects.bulk_create(create_seats)
|
Seat.objects.bulk_create(create_seats)
|
||||||
CartPosition.objects.filter(seat__in=[s.pk for s in current_seats.values()]).delete()
|
CartPosition.objects.filter(seat__in=[s.pk for s in current_seats.values()]).delete()
|
||||||
|
|||||||
Reference in New Issue
Block a user