コード例 #1
0
def __create_if_post_method(context, request):
    if request.method == "POST":
        try:
            flight = __get_create_flight_dto_from_request(request)
            api_service_container.flight_management_service().create(flight)
            context["saved"] = True
        except Exception as e:
            print(e)
            context["saved"] = False
コード例 #2
0
def __edit_if_post_method(context, flight_id: int,
                          request: HttpRequest) -> FlightDetailsDto:
    if request.method == "POST":
        try:
            flight = __get_edit_flight_dto_from_request(flight_id, request)
            api_service_container.flight_management_service().edit(
                flight_id, flight)
            context["saved"] = True
            return __get_flight_details_dto_or_raise_404(flight_id)
        except Exception as e:
            print(e)
            context["saved"] = False
コード例 #3
0
def index(request):
    flights = api_service_container.flight_management_service().list()
    context = {
        "title": "Flights",
        "flights": flights  # list flight dto
    }
    return render(request, 'api/Flight/index.html', context)
コード例 #4
0
def __get_flight_details_dto_or_raise_404(flight_id) -> FlightDetailsDto:
    try:
        flight = api_service_container.flight_management_service().get(
            flight_id)
    except Flight.DoesNotExist:
        raise Http404("The requested flight does not exist")
    return flight
コード例 #5
0
ファイル: booking_views.py プロジェクト: laken11/nites
def create_booking(request):
    flight = api_service_container.flight_management_service(
    ).get_all_for_select_list()
    passenger = api_service_container.passenger_management_service(
    ).get_all_for_select_list()
    context = {"flight": flight, "passenger": passenger}
    __create_if_method_post(context, request)
    if request.method == "POST" and context["saved"]:
        redirect("index_booking")
    return render(request, 'api/Bookings/createBooking.html', context)
コード例 #6
0
def search_flight(request) -> SearchFlightDetailsDto:
    flights = api_service_container.flight_management_service() \
        .search_related_flight(request.GET.get("take_off_point", None), request.GET["take_off_time"],
                               request.GET["destination"])
    context = {
        "flights": flights,
        "take_off_point": request.GET["take_off_point"],
        "take_off_time": request.GET["take_off_time"],
        "destination": request.GET["destination"]
    }
    return render(request, 'api/Flight/searchflight.html', context)
コード例 #7
0
ファイル: booking_views.py プロジェクト: laken11/nites
def edit_booking(request, id):
    booking_details_dto = __get_booking_dto_or_rise_404(id=id)
    flight = api_service_container.flight_management_service(
    ).get_all_for_select_list()
    context = {
        "flight":
        flight,
        "booking":
        booking_details_dto,
        "title":
        f"Edit: booking{booking_details_dto.booking_reference}",
        "take_off_time":
        booking_details_dto.take_off_time.strftime("%Y-%m-%d %H:%M:%S"),
        "id":
        id
    }
    new_booking_details_dto = __edit_if_method_is_post(context, id, request)
    if new_booking_details_dto is not None:
        context["booking"] = new_booking_details_dto
    return render(request, "api/Bookings/editBooking.html", context)
コード例 #8
0
def delete(request, flight_id: int):
    try:
        api_service_container.flight_management_service().delete(flight_id)
        return redirect("index")
    except Exception:
        raise Http404("No such flight exists")