def get(self, region=None, lon=None, lat=None, uri=None, id=None): collection = self.collection args = self.parsers["get"].parse_args() # handle headsign if args.get("headsign"): f = u"vehicle_journey.has_headsign({})".format( protect(args["headsign"])) if args.get("filter"): args["filter"] += " and " + f else: args["filter"] = f # for retrocompatibility purpose for forbid_id in args['__temporary_forbidden_id[]']: args['forbidden_uris[]'].append(forbid_id) if "odt_level" in args and args[ "odt_level"] != "all" and "lines" not in collection: abort(404, message= "bad request: odt_level filter can only be applied to lines") if region is None and lat is None and lon is None: if "external_code" in args and args["external_code"]: type_ = collections_to_resource_type[collection] for instance in i_manager.get_regions(): res = i_manager.instances[instance].has_external_code( type_, args["external_code"]) if res: region = instance id = res break if not region: abort(404, message="Unable to find an object for the uri %s" % args["external_code"]) else: abort(503, message="Not implemented yet") else: user = authentication.get_user(token=authentication.get_token()) authentication.has_access(region, 'ALL', abort=True, user=user) self.region = i_manager.get_region(region, lon, lat) #we store the region in the 'g' object, which is local to a request set_request_timezone(self.region) # change dt to utc if args['since']: args['_original_since'] = args['since'] args['since'] = date_to_timestamp( self.convert_to_utc(args['since'])) if args['until']: args['_original_until'] = args['until'] args['until'] = date_to_timestamp( self.convert_to_utc(args['until'])) if not self.region: return {"error": "No region"}, 404 if uri: if uri[-1] == "/": uri = uri[:-1] uris = uri.split("/") if collection is None: collection = uris[-1] if len(uris) % 2 != 0 else uris[-2] args["filter"] = self.get_filter(uris, args) if collection and id: f = u'{o}.uri={v}'.format( o=collections_to_resource_type[collection], v=protect(id)) if args.get("filter"): args["filter"] += " and " + f else: args["filter"] = f response = i_manager.dispatch(args, collection, instance_name=self.region) return response
def get(self, region=None, lon=None, lat=None, uri=None, id=None): args = self.parsers["get"].parse_args() if args['disable_geojson']: g.disable_geojson = True # for retrocompatibility purpose for forbid_id in args['__temporary_forbidden_id[]']: args['forbidden_uris[]'].append(forbid_id) if "odt_level" in args and args[ "odt_level"] != "all" and "lines" not in self.collection: abort(404, message= "bad request: odt_level filter can only be applied to lines") if args.get("external_code") is not None: type_ = collections_to_resource_type[self.collection] if all(obj is None for obj in (region, lat, lon)): for instance in i_manager.get_regions(): res = i_manager.instances[instance].has_external_code( type_, args["external_code"]) if res: region = instance id = res break if not region: abort(404, message= "Unable to find an object for the external_code %s" % args["external_code"]) else: id = i_manager.instances[region].has_external_code( type_, args["external_code"]) if id == None: abort(404, message= "Unable to find an object for the external_code %s" % args["external_code"]) self.region = i_manager.get_region(region, lon, lat) # we store the region in the 'g' object, which is local to a request set_request_timezone(self.region) # change dt to utc args['_current_datetime'] = self.convert_to_utc( args['_current_datetime']) if args['since']: args['_original_since'] = args['since'] args['since'] = date_to_timestamp( self.convert_to_utc(args['since'])) if args['until']: args['_original_until'] = args['until'] args['until'] = date_to_timestamp( self.convert_to_utc(args['until'])) if not self.region: return {"error": "No region"}, 404 uris = [] if uri: uris = split_uri(uri) if self.collection is None: self.collection = uris[-1] if len(uris) % 2 != 0 else uris[-2] args["filter"] = self.get_filter(uris, args) if self.collection and id: f = u'{o}.uri={v}'.format( o=collections_to_resource_type[self.collection], v=protect(id)) if args.get("filter"): args["filter"] = '({}) and {}'.format(args["filter"], f) else: args["filter"] = f response = i_manager.dispatch(args, self.collection, instance_name=self.region) return response