示例#1
0
文件: seating.py 项目: nerdoc/pretix
def generate_seats(event, subevent, plan, mapping):
    current_seats = {
        s.seat_guid: s
        for s in event.seats.select_related('product').annotate(
            has_op=Count('orderposition')).filter(subevent=subevent)
    }
    create_seats = []
    if plan:
        for ss in plan.iter_all_seats():
            p = mapping.get(ss.category)
            if ss.guid in current_seats:
                seat = current_seats.pop(ss.guid)
                if seat.product != p:
                    seat.product = p
                    seat.save()
            else:
                create_seats.append(
                    Seat(
                        event=event,
                        subevent=subevent,
                        seat_guid=ss.guid,
                        name=ss.name,
                        product=p,
                    ))

    for s in current_seats.values():
        if s.has_op:
            raise SeatProtected(
                _('You can not change the plan since seat "{}" is not present in the new plan and is '
                  'already sold.').format(s.name))

    Seat.objects.bulk_create(create_seats)
    CartPosition.objects.filter(
        seat__in=[s.pk for s in current_seats.values()]).delete()
    Seat.objects.filter(pk__in=[s.pk for s in current_seats.values()]).delete()
示例#2
0
def generate_seats(event, subevent, plan, mapping):
    current_seats = {}
    for s in event.seats.select_related('product').annotate(
            has_op=Count('orderposition'), has_v=Count('vouchers')
    ).filter(subevent=subevent).order_by():
        if s.seat_guid in current_seats:
            s.delete()  # Duplicates should not exist
        else:
            current_seats[s.seat_guid] = s

    def update(o, a, v):
        if getattr(o, a) != v:
            setattr(o, a, v)
            return True
        return False

    create_seats = []
    if plan:
        for ss in plan.iter_all_seats():
            p = mapping.get(ss.category)
            if ss.guid in current_seats:
                seat = current_seats.pop(ss.guid)
                updated = any([
                    update(seat, 'product', p),
                    update(seat, 'name', ss.name),
                    update(seat, 'row_name', ss.row),
                    update(seat, 'seat_number', ss.number),
                    update(seat, 'zone_name', ss.zone),
                    update(seat, 'sorting_rank', ss.sorting_rank),
                    update(seat, 'row_label', ss.row_label),
                    update(seat, 'seat_label', ss.seat_label),
                ])
                if updated:
                    seat.save()
            else:
                create_seats.append(Seat(
                    event=event,
                    subevent=subevent,
                    seat_guid=ss.guid,
                    name=ss.name,
                    row_name=ss.row,
                    seat_number=ss.number,
                    zone_name=ss.zone,
                    sorting_rank=ss.sorting_rank,
                    row_label=ss.row_label,
                    seat_label=ss.seat_label,
                    product=p,
                ))

    for s in current_seats.values():
        if s.has_op:
            raise SeatProtected(_('You can not change the plan since seat "%s" is not present in the new plan and is '
                                  '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)
    CartPosition.objects.filter(seat__in=[s.pk for s in current_seats.values()]).delete()
    Seat.objects.filter(pk__in=[s.pk for s in current_seats.values()]).delete()
示例#3
0
文件: seating.py 项目: zfb103/pretix
def generate_seats(event, subevent, plan, mapping):
    current_seats = {
        s.seat_guid: s for s in
        event.seats.select_related('product').annotate(has_op=Count('orderposition')).filter(subevent=subevent)
    }

    def update(o, a, v):
        if getattr(o, a) != v:
            setattr(o, a, v)
            return True
        return False

    create_seats = []
    if plan:
        for ss in plan.iter_all_seats():
            p = mapping.get(ss.category)
            if ss.guid in current_seats:
                seat = current_seats.pop(ss.guid)
                updated = any([
                    update(seat, 'product', p),
                    update(seat, 'name', ss.name),
                    update(seat, 'row_name', ss.row),
                    update(seat, 'seat_number', ss.number),
                    update(seat, 'zone_name', ss.zone),
                ])
                if updated:
                    seat.save()
            else:
                create_seats.append(Seat(
                    event=event,
                    subevent=subevent,
                    seat_guid=ss.guid,
                    name=ss.name,
                    row_name=ss.row,
                    seat_number=ss.number,
                    zone_name=ss.zone,
                    product=p,
                ))

    for s in current_seats.values():
        if s.has_op:
            raise SeatProtected(_('You can not change the plan since seat "{}" is not present in the new plan and is '
                                  'already sold.').format(s.name))

    Seat.objects.bulk_create(create_seats)
    CartPosition.objects.filter(seat__in=[s.pk for s in current_seats.values()]).delete()
    Seat.objects.filter(pk__in=[s.pk for s in current_seats.values()]).delete()
示例#4
0
文件: seating.py 项目: thegcat/pretix
def generate_seats(event, subevent, plan, mapping, blocked_guids=None):
    current_seats = {}
    for s in event.seats.select_related('product').annotate(
            has_op=Exists(
                OrderPosition.all.filter(
                    seat=OuterRef('pk'),
                    canceled=False,
                ).exclude(order__status__in=(Order.STATUS_CANCELED,
                                             Order.STATUS_EXPIRED))),
            has_v=Count('vouchers')).filter(subevent=subevent).order_by():
        if s.seat_guid in current_seats:
            s.delete()  # Duplicates should not exist
        else:
            current_seats[s.seat_guid] = s

    def update(o, a, v):
        if getattr(o, a) != v:
            setattr(o, a, v)
            return True
        return False

    create_seats = []
    if plan:
        for ss in plan.iter_all_seats():
            p = mapping.get(ss.category)
            if ss.guid in current_seats:
                seat = current_seats.pop(ss.guid)
                updated = any([
                    update(seat, 'product', p),
                    update(seat, 'row_name', ss.row),
                    update(seat, 'seat_number', ss.number),
                    update(seat, 'zone_name', ss.zone),
                    update(seat, 'sorting_rank', ss.sorting_rank),
                    update(seat, 'row_label', ss.row_label),
                    update(seat, 'seat_label', ss.seat_label),
                    update(seat, 'x', ss.x),
                    update(seat, 'y', ss.y),
                ] + ([update(seat, 'blocked', ss.guid in
                             blocked_guids)] if blocked_guids else []))
                if updated:
                    seat.save()
            else:
                create_seats.append(
                    Seat(
                        event=event,
                        subevent=subevent,
                        seat_guid=ss.guid,
                        row_name=ss.row,
                        seat_number=ss.number,
                        zone_name=ss.zone,
                        sorting_rank=ss.sorting_rank,
                        row_label=ss.row_label,
                        seat_label=ss.seat_label,
                        x=ss.x,
                        y=ss.y,
                        blocked=bool(blocked_guids
                                     and ss.guid in blocked_guids),
                        product=p,
                    ))

    for s in current_seats.values():
        if s.has_op:
            raise SeatProtected(
                _(
                    'You can not change the plan since seat "%s" is not present in the new plan and is '
                    '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)
    CartPosition.objects.filter(
        seat__in=[s.pk for s in current_seats.values()]).delete()
    OrderPosition.all.filter(
        Q(canceled=True)
        | Q(order__status__in=(Order.STATUS_CANCELED, Order.STATUS_EXPIRED)),
        seat__in=[s.pk for s in current_seats.values()],
    ).update(seat=None)
    Seat.objects.filter(pk__in=[s.pk for s in current_seats.values()]).delete()