Exemple #1
0
def delete_passenger(request, passenger_id):
    if request.user.has_perm('app.delete_passenger'):
        airline_service_provider.passenger_management_service(
        ).delete_passenger(passenger_id)
        return redirect('list_passenger')
    else:
        context = {'message': 'You are not authorised'}
Exemple #2
0
def __edit_if_post(request, passenger_id, user_id, context):
    if request.method == 'POST':
        try:
            passenger = __set_passenger_attribute_edit(request, user_id)
            airline_service_provider.passenger_management_service(
            ).edit_passenger(passenger_id, passenger)
            context['saved'] = 'success'
            return airline_service_provider.passenger_management_service(
            ).passengers_details(user_id)
        except Passenger.DoesNotExist as e:
            print('Cannot Edit a Passenger that does not exist!')
            raise e
Exemple #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)
Exemple #4
0
def register_booking(request, flight_id):
    if request.user.has_perm('app.add_booking'):
        flights = airline_service_provider.flight_management_service(
        ).flight_details(flight_id=flight_id)
        flight_price = __get_flight_price(flight_id)
        user_id = request.user.id
        passenger = airline_service_provider.passenger_management_service(
        ).passengers_details(user_id)
        context = {
            'title': 'Fill in your details',
            'flights': flights,
            'flight_id': flight_id,
            'flight_price': flight_price,
            'first_name': request.user.first_name,
            'last_name': request.user.last_name,
            'email': request.user.email,
            'phone': passenger.phone,
            'address': passenger.address,
            'registration_number': passenger.registration_number,
            'passenger_id': passenger.id,
            'booking_id': ''
        }
        __create_if_post_method(request, context)
        if request.method == 'POST' and context['saved']:
            booking_id = context['booking_id']
            return redirect('booking_details', booking_id)
        return render(request, 'booking/register_booking.html', context)
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
Exemple #5
0
def __get_passenger_details_or_raise_error(passenger_id):
    try:
        result = airline_service_provider.passenger_management_service(
        ).passengers_details(passenger_id)
        return result
    except Passenger.DoesNotExist as e:
        print('Not Found')
        raise e
Exemple #6
0
def list_passenger(request):
    if request.user.has_perm('app.view_passenger'):
        passengers = airline_service_provider.passenger_management_service(
        ).list_passenger()
        context = {'title': 'List of Passengers', 'passengers': passengers}
        return render(request, 'passenger/list_passenger.html', context)
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
Exemple #7
0
def __create_if_post(request, context):
    if request.method == 'POST':
        try:
            passenger = __set_passenger_attribute_request(request)
            password = passenger.password
            confirm = passenger.confirm_password
            if password == confirm:
                passenger.registration_number = str(uuid.uuid4()).replace(
                    '-', '')[0:10].upper()
                airline_service_provider.passenger_management_service(
                ).register_passenger(passenger)
                context['saved'] = 'success'
                context['message'] = 'saved'
                return passenger
            else:
                context['saved'] = False
        except Exception as e:
            print(e)
            context['saved'] = 'error'
Exemple #8
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