Exemplo n.º 1
0
 def get(self, trip_id, trip_headsign):
     trip_id = unquote(trip_id)
     trip = Trip.get_by_key_name('trip_' + trip_id)
     if trip:
         path = os.path.join(os.path.dirname(__file__), 'templates/trip.kml')
         template_values = {
             'trip': trip,
         }
         self.response.headers['Content-Type'] = 'application/vnd.google-earth.kml+xml'
         self.response.out.write(template.render(path, template_values))
     else:
         self.error(404)
         return self.response.out.write('Erro - Pagina nao encontrada')
Exemplo n.º 2
0
    def get(self, trip_id):
        "Returns encoded polyline path from trip_id"

        trip_id = unquote(trip_id)
        trip = Trip.get_by_key_name('trip_' + trip_id)
        stops = Stop.get_by_key_name(trip.stops)
        stops = filter(lambda s: s is not None, stops)
        stops = filter(lambda s: s.location is not None, stops)
        def serializable_stop(stop):
            return (stop.id,
                    stop.location.lat,
                    stop.location.lon,
                    stop.name)

        stop_locations = [serializable_stop(stop) for stop in stops]

        if trip:
            data = {'points': trip.shape_encoded_polyline,
                    'levels': trip.shape_encoded_levels,
                    'color': trip.route.color,
                    'stops': stop_locations}
            self.response.out.write(simplejson.dumps(data))
Exemplo n.º 3
0
    def get(self, route_id=None, description=None):
        route = Route.get_by_key_name(unquote(route_id))
        if route:
            trips = route.trip_set.fetch(1000)
            trip_id = self.request.get('trip') or trips[0].id

            trip = None
            for trip_loop in trips:
                if trip_loop.id == trip_id:
                    trip = trip_loop
                    break

            if trip is None:
                trip = trips[0]

            similars = Trip.get_by_key_name(trip.similars)

            template_values = {'route': route,
                               'trip': trip,
                               'trips': trips,
                               'similars': similars }
            path = os.path.join(os.path.dirname(__file__), 'templates/route.html')
            self.response.out.write(template.render(path, template_values))
        else:
            #Old urls used trip id. If this is the case, redirect
            trip_id = route_id
            trip = Trips.all().filter("trip_id =", unquote(trip_id)).get()

            if trip:
                route = Route.get_by_key_name(trip.route_id)
                if route:
                    self.redirect(route.get_absolute_url(), permanent=True)
                    return

            #Not found
            self.error(404)
            self.response.out.write('404 - Pagina nao encontrada')