Ejemplo n.º 1
0
def delete_aircraft(request, aircraft_id):
    if request.user.has_perm('app.delete_aircraft'):
        airline_service_provider.aircraft_management_service().delete_aircraft(
            aircraft_id)
        return redirect('list_aircraft')
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
Ejemplo n.º 2
0
def __edit_if_post_method(request, aircraft_id: int, context):
    if request.method == 'POST':
        try:
            aircraft = __set_aircraft_attribute_from_request_edit(
                request, aircraft_id)
            aircraft.date_updated = datetime.date.today()
            airline_service_provider.aircraft_management_service(
            ).edit_aircraft(aircraft_id, aircraft)
            context['saved'] = 'success'
            return __get_aircraft_details_or_raise_404(request, aircraft_id)
        except Exception as e:
            print(e)
            context['saved'] = 'error'
Ejemplo n.º 3
0
def __create_if_post_method(request, context):
    try:
        if request.method == 'POST':
            aircraft = __set_aircraft_attribute_from_request(request)
            aircraft.date_created = datetime.date.today()
            aircraft.aircraft_number = str(uuid.uuid4()).replace(
                '-', '')[0:10].upper()
            airline_service_provider.aircraft_management_service(
            ).register_aircraft(aircraft)
            # return 'ok'
            context['saved'] = 'success'
        return context
    except Exception as e:
        print(e)
        context['saved'] = 'error'
Ejemplo n.º 4
0
def __get_aircraft_details_or_raise_404(request, aircraft_id: int):
    try:
        aircraft = airline_service_provider.aircraft_management_service(
        ).aircraft_details(aircraft_id)
        return aircraft
    except Aircraft.DoesNotExist:
        raise Http404('Aircraft does not exist!')
Ejemplo n.º 5
0
def list_aircraft(request):
    if request.user.has_perm('app.view_aircraft'):
        aircrafts = airline_service_provider.aircraft_management_service(
        ).list_aircraft()
        context = {'title': 'List Aircraft', 'aircrafts': aircrafts}
        return render(request, 'aircraft/list_aircraft.html', context)
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
Ejemplo n.º 6
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
Ejemplo n.º 7
0
def register_flight(request):
    if request.user.has_perm('app.add_flight'):
        aircrafts = airline_service_provider.aircraft_management_service(
        ).get_all_for_selected_list()
        context = {'aircrafts': aircrafts}

        __create_if_post_method(request, context)
        if request.method == 'POST' and context['saved']:
            return redirect('list_flight')
        return render(request, 'flight/register_flight.html', context)
    else:
        context = {'message': 'You are not allowed here'}
        return render(request, 'error_message.html', context)
Ejemplo n.º 8
0
def edit_flight(request, flight_id: int):
    if request.user.has_perm('app.change_flight'):
        aircrafts = airline_service_provider.aircraft_management_service(
        ).get_all_for_selected_list()
        editing_flight = __get_flight_or_raise_error(flight_id)
        context = {
            'flight': editing_flight,
            'arrival_time': editing_flight.arrival_time.strftime("%H:%M"),
            'departure_date':
            editing_flight.departure_date.strftime("%Y-%m-%d"),
            'aircrafts': aircrafts
        }
        new_editing_flight = __edit_if_post(request, flight_id, context)
        if new_editing_flight is not None:
            context['flight'] = new_editing_flight
            return redirect('list_flight')
        return render(request, 'flight/edit_flight.html', context)
    else:
        context = {'message': 'You are not authorised to view this page!'}
        return render(request, 'error_message.html', context)