示例#1
0
def index(request):
    """
    Show transit information
    """

    pathbar = Pathbar()
    # pathbar.append(_("Transit information") , 'gogogo.views.transit.index',None)

    loader = ListLoader(Agency)
    loader.load()

    data = loader.get_data()
    agency_list = []
    for agency in data:
        entity = createEntity(agency)
        entity = trEntity(entity, request)
        entity["type_name"] = TransitTypeProperty.get_type_name(entity["type"])

        agency_list.append(entity)

    return render_to_response(
        request,
        "gogogo/transit/index.html",
        {
            "page_title": _("Transit information"),
            "pathbar": pathbar,
            "model_kind": "agency",
            "agency_list": agency_list,
            "agency_type_name_list": TransitTypeProperty.get_basic_type_name_list(),
        },
    )
示例#2
0
def route(request, agency_id, route_id):
    """
    Browse the information of a route data. 

    It is the most expensive call in the system.
    """

    route_loader = RouteLoader(route_id)
    route_loader.load()

    lang = MLStringProperty.get_current_lang(request)

    agency_entity = trEntity(route_loader.get_agency(), request)
    route_entity = trEntity(route_loader.get_entity(), request)
    route_entity["type"] = TransitTypeProperty.get_type_name(route_entity["type"])

    trip_list = []

    endpoint_id_list = {}
    endpoint_list = []

    for trip_loader in route_loader.get_trip_list():
        entity = trEntity(trip_loader.get_entity(), request)
        entity["first"] = trEntity(trip_loader.first, request)
        entity["last"] = trEntity(trip_loader.last, request)
        entity["stop_list"] = [trEntity(stop, request) for stop in trip_loader.stop_entity_list]
        trip_list.append(entity)

        for type in ("first", "last"):
            stop = entity[type]
            if stop == None:
                continue
            id = stop["id"]
            if id not in endpoint_id_list:
                endpoint_id_list[id] = True
                endpoint_list.append(stop["latlng"].lat)
                endpoint_list.append(stop["latlng"].lon)

    trip_id_list = [trip["id"] for trip in trip_list]
    pathbar = Pathbar(agency=(agency_entity, route_entity))

    return render_to_response(
        request,
        "gogogo/transit/route.html",
        {
            "page_title": agency_entity["name"] + " - " + route_entity["long_name"],
            "pathbar": pathbar,
            "route_kind": "route",
            "trip_kind": "trip",
            "agency": agency_entity,
            "route": route_entity,
            "trip_list": trip_list,
            # "travel_list" : travel_list,
            "endpoint_list": endpoint_list,
            "trip_id_list": trip_id_list,
        },
    )
示例#3
0
def agency(request, agency_id):
    """
    Browse the information of a transport agency
    """

    agency_loader = AgencyLoader(agency_id)
    agency_loader.load()

    agency = trEntity(agency_loader.get_agency_entity(), request)
    agency["type"] = TransitTypeProperty.get_type_name(agency["type"])

    pathbar = Pathbar(agency=(agency,))

    route_list = agency_loader.get_route_list()
    route_list = [trEntity(route, request) for route in route_list]

    trip_id_list = agency_loader.get_trip_id_list()

    showMap = agency["show_map_in_transit_page"]

    t = loader.get_template("gogogo/transit/agency.html")
    c = RequestContext(
        request,
        {
            "page_title": agency["name"],
            "pathbar": pathbar,
            "agency_kind": "agency",
            "route_kind": "route",
            "agency": agency,
            "showMap": showMap,
            "trip_id_list": trip_id_list,
            "route_list": route_list,
        },
    )

    return HttpResponse(t.render(c))