Ejemplo n.º 1
0
def __edit_if_post_method(request, flight_id: int, context):
    if request.method == 'POST':
        try:
            flight = __get_attribute_from_request_edit(flight_id, request)
            flight.date_updated = datetime.date.today()
            app_service_provider.flight_management_service().edit_flight(
                flight_id, flight)
            context['saved'] = True
            return context
        except Exception as e:
            context['saved'] = False
            raise e
Ejemplo n.º 2
0
def __create_flight_if_post_method(request, context):
    if request.method == 'POST':
        try:
            flight = __set_attribute_from_request(request)
            flight.flight_number = str(uuid.uuid4()).replace('-',
                                                             '')[0:10].upper()
            flight.date_created = datetime.date.today()
            app_service_provider.flight_management_service().register_flight(
                flight)
            context['saved'] = True
        except Exception as e:
            context['saved'] = False
            raise e
        return context
Ejemplo n.º 3
0
def __get_flight_or_rise_404(flight_id: int):
    try:
        flight = app_service_provider.flight_management_service(
        ).flight_details(flight_id)
        return flight
    except Exception:
        raise Http404('Flight Dose Not Exit')
Ejemplo n.º 4
0
def search_flight(request):
    takeoff_location = request.POST.get('takeoff_location', False)
    departure_date = request.POST.get('departure_date', '')
    destination = request.POST.get('destination', False)
    flights = app_service_provider.flight_management_service().search_flight(
        takeoff_location, destination, departure_date)
    context = {'flights': flights}
    return render(request, 'Flight/search_flight.html', context)
Ejemplo n.º 5
0
def flight_details(request, flight_id: int):
    flight = app_service_provider.flight_management_service().flight_details(
        flight_id)
    context = {'flight': flight, 'title': 'Flight Details'}
    return render(request, 'Flight/flight_details.html', context)
Ejemplo n.º 6
0
def list_flight(request):
    flights = app_service_provider.flight_management_service().list_flight()
    context = {'flights': flights, 'title': 'Flights'}
    return render(request, 'Flight/list_flight.html', context)
Ejemplo n.º 7
0
def delete_flight(request, flight_id: int):
    app_service_provider.flight_management_service().delete_flight(flight_id)
    return redirect('list_flight')