def planes_update(request, plane_id): if request.method == "POST": if Plane.objects.filter(pk=plane_id).count() != 1: return render(request, 'landing/not-found.html', status=404) identifier = request.POST.get("identifier") if Plane.objects.filter(identifier=identifier).count() != 0: return render(request, 'landing/bad-input.html', status=420) plane = Plane.objects.get(pk=plane_id) plane.identifier = identifier plane.size = get_size(request.POST.get("size")) plane.airline = Airline.objects.get(id=request.POST.get("airline")) n = request.POST.get("Current Passenger Count") if n: plane.currentPassengerCount = n n = request.POST.get("Max Passenger Count") if n: plane.maxPassengerCount = n plane.save() return redirect(planes_index) return render( request, 'planes/update.html', { 'plane': Plane.objects.get(pk=plane_id), 'airlines': Airline.objects.all().order_by("name") })
def runways_create(request): if request.method == "POST": identifier = request.POST.get("identifier") if Runway.objects.filter(identifier=identifier).count() != 0: return render(request, 'landing/bad-input.html', status=420) runway = Runway() runway.identifier = identifier runway.size = get_size(request.POST.get( "size")) # no need to validate because select statement runway.airport = Airport.objects.get(pk=request.POST.get("airport")) runway.save() return redirect(runways_index) return render(request, 'runways/create.html', {'airports': Airport.objects.all().order_by("name")})
def runways_update(request, runway_id): if Runway.objects.filter(pk=runway_id).count() != 1: return render(request, 'landing/not-found.html', status=404) if request.method == "POST": identifier = request.POST.get("identifier") if not validate_identifier(identifier, Runway, runway_id): return render(request, 'landing/bad-input.html', status=420) runway = Runway.objects.get(pk=runway_id) runway.identifier = identifier runway.size = get_size(request.POST.get("size")) runway.airport = Airport.objects.get(pk=request.POST.get("airport")) runway.save() return redirect(runways_index) return render( request, 'runways/update.html', { 'runway': Runway.objects.get(pk=runway_id), 'airports': Airport.objects.all().order_by("name") })
def gates_update(request, gate_id): if Gate.objects.filter(pk=gate_id).count() != 1: return render(request, 'landing/not-found.html', status=404) if request.method == "POST": identifier = request.POST.get("identifier") if not validate_identifier(identifier, Gate, gate_id): return render(request, 'landing/bad-input.html', status=420) gate = Gate.objects.get(pk=gate_id) gate.identifier = identifier gate.size = get_size(request.POST.get("size")) gate.airport = Airport.objects.get(pk=request.POST.get("airport")) gate.save() return redirect(gates_index) return render( request, 'gates/update.html', { 'gate': Gate.objects.get(pk=gate_id), 'airports': Airport.objects.all().order_by("name") })