Fix note mandatory && subscriber creation

This commit is contained in:
Kuroshini 2019-10-16 14:11:07 +03:00
parent 445d76df75
commit 2cd69e02cb
2 changed files with 8 additions and 4 deletions

View File

@ -27,10 +27,12 @@ class AbstractBookingService(ABC):
self.url = settings.LASTABLE_SERVICE
@staticmethod
def get_certain_keys(d: dict, keys_to_preserve: set, required=True) -> dict:
def get_certain_keys(d: dict, keys_to_preserve: set, required: set = {}, check: bool = True) -> dict:
""" Helper """
if required:
diff = keys_to_preserve - d.keys()
if len(required) == 0 and check:
required = keys_to_preserve.copy()
if required and check:
diff = required - d.keys()
if diff:
raise serializers.ValidationError({field: _(f'This field is required') for field in diff})
return {key: d[key] for key in d.keys() & keys_to_preserve}

View File

@ -96,13 +96,15 @@ class UpdatePendingBooking(generics.UpdateAPIView):
data['pending_booking_id'] = instance.pending_booking_id
r = service.update_booking(service.get_certain_keys(data, {
'email', 'phone', 'last_name', 'first_name', 'country_code', 'pending_booking_id', 'note',
}, {
'email', 'phone', 'last_name', 'first_name', 'country_code', 'pending_booking_id',
}))
if isinstance(r, Response):
return r
if data.get('newsletter'):
Subscriber.objects.make_subscriber(email=data['email'], country_code=data['country_code'],
locale=request.locale, ip_address=get_user_ip(request),
user=request.user)
user=None)
if service.response:
# если есть предоплата, возвращаем фронту страйп-ключ для совершения оплаты и цену
amount = service.response.get('amount')