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))
def get(self, route_type=None, route_type_description=None): base_query = Route.all().order("id") if route_type: base_query = base_query.filter('type =', int(route_type)) page = int(self.request.get('pagina', default_value=1)) routes = base_query.fetch(PAGESIZE + 1, offset=(page - 1) * PAGESIZE) has_next = len(routes) > PAGESIZE for route in routes: if route.preview_image_url is None: route.set_preview_image_url() if route_type: base_url = '/lista/%s/%s' % (route_type, route_type_description) else: base_url = '/' template_values = { 'routes': routes, 'route_type': route_type_description, 'page': page, 'back_url': '%s?pagina=%d' % (base_url, page - 1) if page > 1 else None, 'next_url': '%s?pagina=%d' % (base_url, page + 1) if has_next else None, } path = os.path.join(os.path.dirname(__file__), 'templates/list.html') self.response.out.write(template.render(path, template_values))
def search_routes(search_string, offset=0, limit=10): base_query = Route.all() words = get_words(search_string) if search_string.endswith(' '): #search routes that have all entire words for word in words: base_query = base_query.filter('searchable_words =', word) elif len(words) == 0: return [] elif len(words) == 1: #search by routes that have word starting with text word = words[0] base_query = base_query.filter('searchable_words >=', word) base_query = base_query.filter('searchable_words <', word[:-1] + chr(ord(word[-1]) + 1)) else: #search by routes that have all first words complete and a word starting with last word for word in words[:-1]: base_query = base_query.filter('searchable_words =', word) last_word = words[-1] #need to order in memory (exploding indexes) routes = [route for route in base_query.fetch(1000) if any([word.startswith(last_word) for word in route.searchable_words])] return routes[offset:limit] return base_query.fetch(offset=offset, limit=limit)
def create_search_list(): def route_dict(route): return {'url': route.get_absolute_url(), 'text': "%s - %s" % (route.short_name, route.long_name)} routes = Route.all().fetch(2000) data = [route_dict(route) for route in routes] return simplejson.dumps(data)
def get(self): from util import slugify def absolute_url(route): return 'http://www.toape.com.br/%s/%s' % (route.id, slugify(route.long_name)) routes = Route.all().fetch(2000) urls = ['http://www.toape.com.br'] urls += [absolute_url(route) for route in routes] self.response.headers['Content-Type'] = "text/plain" self.response.out.write('\n'.join(urls))