From 09a7987b613d30abfffc8470f1f09215b9e83c13 Mon Sep 17 00:00:00 2001 From: Mira Date: Fri, 26 Jul 2024 17:12:05 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Raphael Michel --- doc/api/resources/seats.rst | 10 +++++----- src/pretix/api/serializers/event.py | 10 +++++----- src/pretix/api/views/event.py | 2 -- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/doc/api/resources/seats.rst b/doc/api/resources/seats.rst index 43479cfcdd..b00fc596d9 100644 --- a/doc/api/resources/seats.rst +++ b/doc/api/resources/seats.rst @@ -1,9 +1,9 @@ .. _`rest-reusablemedia`: Seats -============== +===== -Seat resources represent the seats in a seating plan in a specific event or subevent. +The seat resource represents the seats in a seating plan in a specific event or subevent. Resource description -------------------- @@ -25,9 +25,6 @@ seat_label string Additional labe seat_guid string Identifier of the seat within the seating plan product integer blocked boolean Whether this seat is blocked manually. -sorting_rank integer -x float -y float orderposition integer / object Internal ID of an order position reserving this seat. cartposition integer / object Internal ID of a cart position reserving this seat. voucher integer / object Internal ID of a voucher reserving this seat. @@ -88,6 +85,7 @@ Endpoints :statuscode 200: no error :statuscode 401: Authentication failure :statuscode 403: The requested organizer does not exist **or** you have no permission to view this resource. + :statuscode 404: Endpoint without subevent id was used for event with subevents, or vice versa. .. http:get:: /api/v1/organizers/(organizer)/events/(event)/seats/(id)/ .. http:get:: /api/v1/organizers/(organizer)/events/(event)/subevents/(subevent_id)/seats/(id)/ @@ -126,6 +124,7 @@ Endpoints :statuscode 200: no error :statuscode 401: Authentication failure :statuscode 403: The requested organizer does not exist **or** you have no permission to view this resource. + :statuscode 404: Seat does not exist; or the endpoint without subevent id was used for event with subevents, or vice versa. .. http:patch:: /api/v1/organizers/(organizer)/events/(event)/seats/(id)/ .. http:patch:: /api/v1/organizers/(organizer)/events/(event)/subevents/(id)/seats/(id)/ @@ -168,3 +167,4 @@ Endpoints :statuscode 400: The seat could not be modified due to invalid submitted data :statuscode 401: Authentication failure :statuscode 403: The requested organizer or event does not exist **or** you have no permission to change this resource. + :statuscode 404: Seat does not exist; or the endpoint without subevent id was used for event with subevents, or vice versa. diff --git a/src/pretix/api/serializers/event.py b/src/pretix/api/serializers/event.py index b93d0463f0..0cf4d4dcb2 100644 --- a/src/pretix/api/serializers/event.py +++ b/src/pretix/api/serializers/event.py @@ -971,15 +971,15 @@ class ItemMetaPropertiesSerializer(I18nAwareModelSerializer): fields = ('id', 'name', 'default', 'required', 'allowed_values') -def prefetch_by_id(items, manager, id_attr, id_filter, target_attr): +def prefetch_by_id(items, qs, id_attr, id_filter, target_attr): """ Prefetches a related object on each item in the given list of items by searching by id or another - unique field. The id value is read from the attribute on item specified in `id_attr`, searched on manager by the + unique field. The id value is read from the attribute on item specified in `id_attr`, searched on queryset `qs` by the field specified in `id_filter`, and the resulting prefetched model object is stored into `target_attr` on the item. """ ids = [getattr(item, id_attr) for item in items if getattr(item, id_attr)] if ids: - result = manager.order_by(id_filter).distinct(id_filter).in_bulk(id_list=ids, field_name=id_filter) + result = qs.order_by(id_filter).distinct(id_filter).in_bulk(id_list=ids, field_name=id_filter) for item in items: setattr(item, target_attr, result.get(getattr(item, id_attr))) @@ -993,12 +993,12 @@ class SeatSerializer(I18nAwareModelSerializer): model = Seat read_only_fields = ( 'id', 'subevent', 'zone_name', 'row_name', 'row_label', - 'seat_number', 'seat_label', 'seat_guid', 'product', 'sorting_rank', 'x', 'y', + 'seat_number', 'seat_label', 'seat_guid', 'product', 'orderposition', 'cartposition', 'voucher', ) fields = ( 'id', 'subevent', 'zone_name', 'row_name', 'row_label', - 'seat_number', 'seat_label', 'seat_guid', 'product', 'blocked', 'sorting_rank', 'x', 'y', + 'seat_number', 'seat_label', 'seat_guid', 'product', 'blocked', 'orderposition', 'cartposition', 'voucher', ) diff --git a/src/pretix/api/views/event.py b/src/pretix/api/views/event.py index ec22c6a12b..cce3ecd21f 100644 --- a/src/pretix/api/views/event.py +++ b/src/pretix/api/views/event.py @@ -697,8 +697,6 @@ class SeatViewSet(ConditionalListView, viewsets.ModelViewSet): ctx['order_context'] = { 'event': self.request.event, 'pdf_data': None, - 'include': self.request.query_params.getlist('order_include'), - 'exclude': self.request.query_params.getlist('order_exclude'), } return ctx