def search(request): """ Route searching """ error = None agency = None if "agency" in request.GET: agency_id = request.GET['agency'] agency = db.Key.from_path(Agency.kind(),agency_id) if "keyword" not in request.GET: return render_to_response( request, 'gogogo/route/search.html' ,{ 'page_title': _("Route searching"), 'result' : [], 'error' : _("Error! No keyword provided!") }) keyword = request.GET['keyword'] keyword = keyword.lower() route_list_loader = ListLoader(Route) route_list_loader.load() route_list = route_list_loader.get_data() result = [] agency_property = getattr(Route,"agency") for route in route_list: if agency: key = agency_property.get_value_for_datastore(route) if agency != key: continue if route.short_name.lower().find(keyword) != -1: result.append(route) continue for name in route.long_name: if name.lower().find(keyword)!= -1: result.append(route) continue result = [trEntity(createEntity(route),request) for route in result ] return render_to_response( request, 'gogogo/route/search.html' ,{ 'page_title': _("Route searching"), 'result' : result, 'error' : error })
def agency_pre_save(sender, **kwargs): from gogogo.models.loaders import AgencyLoader,ListLoader from gogogo.models.cache import removeCache instance = kwargs['instance'] if instance.is_saved(): loader = AgencyLoader(instance.key().id_or_name()) loader.remove_cache() list_loader = ListLoader(Agency) list_loader.remove_cache()