From 7956074d8bbcebeb187c81f2f4283a71a71cc4e4 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 26 Aug 2020 15:20:44 +0200 Subject: [PATCH] API: Add exclude parameter to check-in lists --- doc/api/resources/checkinlists.rst | 3 ++- src/pretix/api/serializers/checkin.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/api/resources/checkinlists.rst b/doc/api/resources/checkinlists.rst index 0c1cf26467..385af46c24 100644 --- a/doc/api/resources/checkinlists.rst +++ b/doc/api/resources/checkinlists.rst @@ -58,7 +58,7 @@ rules object Custom check-in .. versionchanged:: 3.11 - The ``subevent_match`` filter has been added. + The ``subevent_match`` and ``exclude`` query parameters have been added. Endpoints --------- @@ -114,6 +114,7 @@ Endpoints :query integer page: The page number in case of a multi-page result set, default is 1 :query integer subevent: Only return check-in lists of the sub-event with the given ID :query integer subevent_match: Only return check-in lists that are valid for the sub-event with the given ID (i.e. also lists valid for all subevents) + :query string exclude: Exclude a field from the output, e.g. ``checkin_count``. Can be used as a performance optimization. Can be passed multiple times. :param organizer: The ``slug`` field of the organizer to fetch :param event: The ``slug`` field of the event to fetch :statuscode 200: no error diff --git a/src/pretix/api/serializers/checkin.py b/src/pretix/api/serializers/checkin.py index 5ac2c44958..a49f3b860b 100644 --- a/src/pretix/api/serializers/checkin.py +++ b/src/pretix/api/serializers/checkin.py @@ -17,6 +17,17 @@ class CheckinListSerializer(I18nAwareModelSerializer): 'include_pending', 'auto_checkin_sales_channels', 'allow_multiple_entries', 'allow_entry_after_exit', 'rules') + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + for exclude_field in self.context['request'].query_params.getlist('exclude'): + p = exclude_field.split('.') + if p[0] in self.fields: + if len(p) == 1: + del self.fields[p[0]] + elif len(p) == 2: + self.fields[p[0]].child.fields.pop(p[1]) + def validate(self, data): data = super().validate(data) event = self.context['event']