From 70b21107448547e904c9af7e5bad28efeb5139ca Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Wed, 16 Oct 2019 14:11:07 +0300 Subject: [PATCH] Fix booking slots order --- apps/booking/views.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/booking/views.py b/apps/booking/views.py index cdadc768..73f6f55e 100644 --- a/apps/booking/views.py +++ b/apps/booking/views.py @@ -14,6 +14,12 @@ class CheckWhetherBookingAvailable(generics.GenericAPIView): """ Checks which service to use if establishmend is managed by any """ _VALID_GUESTONLINE_PERIODS = {'lunch', 'dinner', 'afternoon', 'breakfast'} + _GUESTONLINE_PERIODS_TO_PRIOR = { + 'breakfast': 1, + 'lunch': 2, + 'afternoon': 3, + 'dinner': 4, + } permission_classes = (permissions.AllowAny,) serializer_class = CheckBookingSerializer @@ -32,7 +38,7 @@ class CheckWhetherBookingAvailable(generics.GenericAPIView): period_template = iter(periods_by_name.values()).__next__().copy() period_template.pop('total_left_seats') - period_template.pop('hours') + period_template['hours'] = [] period_template.pop('period') processed_periods = [ @@ -46,7 +52,8 @@ class CheckWhetherBookingAvailable(generics.GenericAPIView): for unnamed_period in unnamed_periods: processed_periods.append(unnamed_period) - response['periods'] = processed_periods + response['periods'] = sorted(processed_periods, + key=lambda x: self._GUESTONLINE_PERIODS_TO_PRIOR[x.get('period', 'lunch')]) return response