Exemple #1
0
 def get(self):
   action = cgi.escape(self.request.get('action'))
   
   if(action == 'load'):
     routename = cgi.escape(self.request.get('routename'))
     
     routes = Route.gql("WHERE name = :1", routename).fetch(1)
     
     if(len(routes) == 0):
       self.response.out.write("No route with name %s" % routename)
       return
     
     route = routes[0];
     
     logging.info('Loading route %s', route.name)
     
     vertices = []
     for vertex in route.vertex_set:
       vertices.append({'lat': vertex.lat, 'lng': vertex.lng})
       logging.info('Loaded vertex with lat %s and lng %s', vertex.lat, vertex.lng)
     
     result = {'vertices': vertices, 'routename': routename };
     
     self.response.out.write(simplejson.dumps(result))
   
   elif action == 'allnames':        
     result = []
     
     for route in Route.all():
       logging.info('Found route name %s', route.name);
       result.append(route.name)
   
     self.response.out.write(simplejson.dumps(result))
Exemple #2
0
 def post(self):
   if(self.request.get('action') == 'save'):
     routename = self.request.get('name')
     
     routes = Route.gql("WHERE name = :1", routename).fetch(1)
     if len(routes) > 0:
         self.response.out.write('Route %s already exists.' % routename)
         return
         
     json_route = simplejson.loads(self.request.get('route'))
     logging.info('JSON route = %s', json_route)
     
     vertices = [latLng.split(',') for latLng in json_route]
     
     route = Route()
     route.name = routename
     route.put()
     
     logging.info('Inserted route with name %s and id %s', route.name, route.key())
     
     for index in range(0, len(vertices)):
         vertex = Vertex()
         vertex.lat = float(str(vertices[index][0]))
         vertex.lng = float(str(vertices[index][1]))
         vertex.route = route
         vertex.put()
         logging.info('Inserted vertex %s, %s on route %s with id %s', vertex.lat, vertex.lng, vertex.route.name, vertex.key())
     
     self.response.out.write('Success')