Exemplo n.º 1
0
def recent_flights(request):
    """
    Returns num list of flights, sorted by recency. No bounding area.
    
    Arguments:
    num: the number you want to return
    """
    flights = Rating.objects.all().order_by("-id")
    json = flights_as_json(flights, MAX_FLIGHTS)
    return HttpResponse(json, mimetype="application/json")
Exemplo n.º 2
0
def flights_for_airline(request, iata_code):
    """
    Returns a list of flights for a given carrier.
    
    Arguments:
    carrier_code: 2 letter IATA carrier code
    """
    flights = Rating.objects.filter(airline__iata_code=iata_code)
    json = flights_as_json(flights, MAX_FLIGHTS)
    return HttpResponse(json, mimetype="application/json")
Exemplo n.º 3
0
def flights_for_username(request, username):
    """
    Returns a list of flights for a given username.
    
    Arguments:
    username: the username that you are looking for.
    """
    flights = Rating.objects.filter(name=username)
    json = flights_as_json(flights, MAX_FLIGHTS)
    return HttpResponse(json, mimetype="application/json")
Exemplo n.º 4
0
def flights_for_boundary(request, south, west, north, east):
    """
    Returns the flights within the bounding box supplied. Since I'm not 
    smart enough to get select_related to do a couple of JOINs onto the 
    aiports, we have to graft the airports onto the flights. We also need to 
    call values() on both the airports and flights since simplejson doesn't 
    understand models.
    """
    try:
        airports = Airport.objects.for_boundary(south, west, north, east)
    except ValueError:
        return HttpResponse("[]", mimetype="application/json")
    flights = Rating.objects.filter(Q(airport_from__in=airports) | 
        Q(airport_to__in=airports))
    json = flights_as_json(flights, MAX_FLIGHTS)
    return HttpResponse(json, mimetype="application/json")