Пример #1
0
def delete_flight(request, flight_id: int):
    if request.user.has_perm('app.delete_flight'):
        airline_service_provider.flight_management_service().delete_flight(
            flight_id)
        return redirect('list_flight')
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
Пример #2
0
def __edit_if_post(request, flight_id: int, context):
    if request.method == 'POST':
        try:
            flight = __set_flight_attribute_edit(request, flight_id)
            flight.date_updated = datetime.date.today()
            airline_service_provider.flight_management_service().edit_flight(
                flight_id, flight)
            context['saved'] = 'success'
            return __get_flight_or_raise_error(flight_id)
        except Exception as e:
            context['saved'] = 'error'
            raise e
Пример #3
0
def __create_if_post_method(request, context):
    try:
        if request.method == 'POST':
            flight = __set_register_flight_attribute(request)
            flight.date_created = datetime.date.today()
            flight.flight_number = str(uuid.uuid4()).replace('-',
                                                             '')[0:10].upper()
            airline_service_provider.flight_management_service(
            ).register_flight(flight)
            context['saved'] = 'success'
        return context
    except Exception as e:
        print(e)
        context['saved'] = 'error'
Пример #4
0
def __get_search_parameters(request, context):
    take_off_location = request.POST['take_off_location']
    destination = request.POST['destination']
    departure_date = request.POST['departure_date']
    try:
        flights = airline_service_provider.flight_management_service(
        ).list_flight()
        flights_list: List[ListFlightDto] = []

        for flight in flights:
            if take_off_location == flight.take_off_location:
                if destination == flight.destination:
                    if departure_date == flight.departure_date:
                        flights_list.append(flight)

                    flights_list.append(flight)

                pass

            pass

        context['flights'] = flights_list

    except Flight.DoesNotExist as e:
        print('No flight to display')
        raise e
Пример #5
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)
Пример #6
0
def __get_flight_or_raise_error(flight_id):
    try:
        result = airline_service_provider.flight_management_service(
        ).flight_details(flight_id)
        return result
    except Flight.DoesNotExist as e:
        print('This Flight does not exist!')
        raise e
Пример #7
0
def list_flight(request):
    if request.user.has_perm('app.view_flight'):
        flights = airline_service_provider.flight_management_service(
        ).list_flight()
        context = {'title': 'List Flight', 'flights': flights}
        return render(request, 'flight/list_flight.html', context)
    else:
        context = {'message': 'You are not authorised!'}
        return render(request, 'error_message.html', context)
Пример #8
0
def __seat_number_generator(request, flight_id, count):
    flights = airline_service_provider.flight_management_service(
    ).flight_details(flight_id=flight_id)
    aircraft_id = flights.aircraft_id
    aircraft = airline_service_provider.aircraft_management_service(
    ).aircraft_details(aircraft_id)
    capacity = aircraft.capacity
    if count <= capacity:
        seat_number = count
        return seat_number
    elif count > capacity:
        raise Exception
Пример #9
0
def __flight_class_and_price(flight_class, flight_id):
    flights = airline_service_provider.flight_management_service(
    ).flight_details(flight_id=flight_id)
    flight_price = flights.price
    if flight_class == 'First':
        flight_price = float(flight_price) * 2
        return flight_price

    elif flight_class == 'Business':
        flight_price = float(flight_price) * 1.5
        return flight_price

    elif flight_class == 'Economic':
        return flight_price
Пример #10
0
def booking_details(request, booking_id):
    if request.user.has_perm('app.view_booking'):
        booking = __get_booking_or_raise_error(booking_id)
        flight = airline_service_provider.flight_management_service(
        ).flight_details(booking.flight_id)
        passenger = Passenger.objects.get(id=booking.passenger_id)

        context = {
            'booking': booking,
            'flight': flight,
            'passenger': passenger,
        }

        return render(request, 'booking/booking_details.html', context)
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
Пример #11
0
def __get_flight_price(flight_id):
    flights = airline_service_provider.flight_management_service(
    ).flight_details(flight_id=flight_id)
    flight_price = flights.price
    return flight_price