Exemple #1
0
def single_route_kml(request, pk, f=False):
    """
    Return a KMZ file representing a single route. The route PK is passed in as
    opposed to a string representation of the route.
    
    If f=true, the pk is the
    pk of the flight the route is connected to (for one case in the logbook
    template where the flight pk is only available)
    """
    
    if f == "f":
        kwarg = {"flight__pk": pk}
    else:
        kwarg = {"pk": pk}
    
    # the actual route object
    route = Route.goof(**kwarg)
    
    #get distinct routebases to make icons with
    rbs = route.routebase_set.all()
    
    # convert routebases into locations
    l = Location.objects.filter(routebase__in=rbs).distinct()
    
    # convert back to dict and just the relevent bits
    r = dict(kml_rendered=route.kml_rendered,
             simple_rendered=route.simple_rendered)
    
    # make the folders
    f = RouteFolder(name="Route", qs=[r], style="#red_line")
    a = AirportFolder(name='Points', qs=l)

    return folders_to_kmz_response([f,a], add_icon=True)