示例#1
0
def delete_booking(request, booking_id):
    if request.user.has_perm('app.delete_booking'):
        try:
            airline_service_provider.booking_management_service(
            ).delete_booking(booking_id)
            return redirect('passenger_booking')
        except Booking.DoesNotExist as e:
            raise e
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
示例#2
0
def __edit_if_post_method(request, context, flight_id, booking_id):
    if request.method == 'POST':
        try:
            booking = __set_booking_attribute_edit(request)
            booking.price = __flight_class_and_price(booking.flight_class,
                                                     flight_id)
            airline_service_provider.booking_management_service().edit_booking(
                booking_id, booking)
            context['saved'] = 'success'
            return __get_booking_or_raise_error(booking_id)
        except Booking.DoesNotExist as e:
            raise e
示例#3
0
def edit_booking(request, booking_id):
    if request.user.has_perm('app.change_booking'):
        booking = airline_service_provider.booking_management_service(
        ).booking_details(booking_id)
        price = booking.price
        flight_id = booking.flight_id
        passenger_id = booking.passenger_id
        user_id = request.user.id
        passenger = airline_service_provider.passenger_management_service(
        ).passengers_details(user_id=user_id)

        context = {
            'title': 'Make your changes',
            'booking': booking,
            'passenger': passenger,
            'price': price,
        }

        new_booking = __edit_if_post_method(request, context, flight_id,
                                            booking_id)
        from app.view.passenger_view.views import __edit_if_post
        new_passenger = __edit_if_post(request, passenger_id, user_id, context)
        if new_booking is not None and new_passenger is not None:
            context['booking'] = new_booking
            context['passenger'] = new_passenger
            return redirect('passenger_booking')
        return render(request, 'booking/edit_booking.html', context)
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
示例#4
0
def __get_booking_or_raise_error(booking_id):
    try:
        booking = airline_service_provider.booking_management_service(
        ).booking_details(booking_id)
        return booking
    except Exception as e:
        raise e
示例#5
0
def __set_seat_if_flight_id_exist(flight_id):
    bookings = airline_service_provider.booking_management_service(
    ).get_all_flight_id_only()
    count = 1
    for flight in bookings:
        if flight_id == flight:
            count += 1
    return count
示例#6
0
def list_booking(request):
    if request.user.has_perm('app.add_flight'):
        bookings = airline_service_provider.booking_management_service(
        ).get_all_bookings()
        context = {
            'bookings': bookings,
        }
        return render(request, 'booking/list_booking.html', context)
    else:
        context = {'message': 'You are not authorised!'}
        return render(request, 'error_message.html', context)
示例#7
0
def __particular_user_booking(request, context):
    user_id = request.user.id
    passenger = airline_service_provider.passenger_management_service(
    ).passengers_details(user_id)
    passenger_id = passenger.id

    try:
        bookings = airline_service_provider.booking_management_service(
        ).get_all_bookings()
        booking_list: List[GetBookingDto] = []

        for booking in bookings:
            if passenger_id == booking.passenger_id:
                booking_list.append(booking)

        context['bookings'] = booking_list
    except Booking.DoesNotExist as e:
        raise e
示例#8
0
def __create_if_post_method(request, context):
    if request.method == 'POST':
        try:
            booking = __set_booking_attribute(request, context)
            booking.booking_reference = str(uuid.uuid4()).replace(
                '-', '')[0:10].upper()
            booking.price = __flight_class_and_price(booking.flight_class,
                                                     booking.flight_id)
            count = __set_seat_if_flight_id_exist(booking.flight_id)
            booking.seat_number = __seat_number_generator(
                request, booking.flight_id, count)
            booking_id = airline_service_provider.booking_management_service(
            ).register_booking(booking)
            context['saved'] = 'success'
            context['booking_id'] = booking_id
            return context
        except Exception as e:
            context['saved'] = 'error'
            raise e