def one_booking(booking_id): """ Deals with one single booking that a user has made. Buttons are displayed on the booking.html page as follows. If booking is active and car is locked: Display the unlock car button for the user to unlock the car Dispay the cancel button for the user If booking is active and car is unlocked: Display return car button for the user :param booking_id: The booking_id is used to identify the perticular booking the user is interacting now with. :return: Re-directs to the home page with a success flash depending on what button the user clicked on, else flashses an error message. """ res = BookingApi.get_booking(booking_id) if "OK" not in res.status: flash("booking non-existant", "danger") return redirect(url_for('main.home')) unlockcarform = UnlockcarForm() cancelbookingform = CancelbookingForm() returncarform = ReturncarForm() enablefaceunlock = Enablefaceunlock() disablefaceunlock = Disablefaceunlock() booking_data = res.get_json() if booking_data['active']: submitted = [*request.form.keys()] for operation in submitted: if operation in BookingButtonOps.supported: getattr(BookingButtonOps, operation)(booking_id) bookingdata = BookingApi.get_booking(booking_id).get_json() if bookingdata.get('error'): flash("booking non-existant", "danger") return redirect(url_for('main.home')) cardata = CarsApi.get_car(bookingdata['car_id']).get_json() show_google_calender_button = False if not bookingdata.get('calendar_id'): show_google_calender_button = True return render_template( 'booking.html', show_google_calender_button=show_google_calender_button, booking=bookingdata, car=cardata, unlockcarform=unlockcarform, cancelbookingform=cancelbookingform, returncarform=returncarform, enablefaceunlock=enablefaceunlock, disablefaceunlock=disablefaceunlock) # etc
def submit_unlock(booking_id): # Updates the car lock status to false when the user unlocks the car. booking = BookingApi.get_booking(booking_id).get_json() g.api_request_json = {'locked': False} res = CarsApi.patch_car(booking['car_id']) if "OK" not in res.status: flash("{}".format(res.get_json()['error']), 'danger') else: flash("car unlocked", "success")