def __init__(self, *args, **kwargs): ResourceUri.__init__( self, authentication=False, output_type_serializer=PlacesSerializer, *args, **kwargs ) self.parsers["get"].add_argument("q", type=six.text_type, required=True, help="The data to search") self.parsers["get"].add_argument( "type[]", type=OptionValue(list(places_type)), action="append", default=["stop_area", "address", "poi", "administrative_region"], help="The type of data to search", ) self.parsers["get"].add_argument( "count", type=default_count_arg_type, default=10, help="The maximum number of places returned" ) self.parsers["get"].add_argument( "search_type", type=int, default=0, hidden=True, help="Type of search: firstletter or type error" ) self.parsers["get"].add_argument( "_main_stop_area_weight_factor", type=float, default=1.0, hidden=True, help="multiplicator for the weight of main stop area", ) self.parsers["get"].add_argument( "admin_uri[]", type=six.text_type, action="append", help="If filled, will restrain the search within the " "given admin uris", ) self.parsers["get"].add_argument("depth", type=DepthArgument(), default=1, help="The depth of objects") self.parsers["get"].add_argument( "_current_datetime", type=DateTimeFormat(), schema_metadata={'default': 'now'}, hidden=True, default=datetime.utcnow(), help='The datetime considered as "now". Used for debug, default is ' 'the moment of the request. It will mainly change the output ' 'of the disruptions.', ) self.parsers['get'].add_argument( "disable_geojson", type=BooleanType(), default=False, help="remove geojson from the response" ) self.parsers['get'].add_argument( "from", type=CoordFormat(nullable=True), help="Coordinates longitude;latitude used to prioritize " "the objects around this coordinate", ) self.parsers['get'].add_argument( "_autocomplete", type=six.text_type, hidden=True, help="name of the autocomplete service, used under the hood", ) self.parsers['get'].add_argument( 'shape', type=geojson_argument(), help='Geographical shape to limit the search.' )
def get(self, region=None, lon=None, lat=None): args = self.parsers["get"].parse_args() self._register_interpreted_parameters(args) if len(args['q']) == 0: abort(400, message="Search word absent") if args['disable_geojson']: g.disable_geojson = True user = authentication.get_user(token=authentication.get_token(), abort_if_no_token=False) if args['shape'] is None and user and user.shape: args['shape'] = json.loads(user.shape) if user and user.default_coord: if args['from'] is None: args['from'] = CoordFormat()(user.default_coord) else: if args['from'] == '': raise InvalidArguments("if 'from' is provided it cannot be null") # If a region or coords are asked, we do the search according # to the region, else, we do a word wide search if any([region, lon, lat]): self.region = i_manager.get_region(region, lon, lat) timezone.set_request_timezone(self.region) response = i_manager.dispatch(args, "places", instance_name=self.region) else: available_instances = get_all_available_instances(user) autocomplete = global_autocomplete.get('bragi') if not autocomplete: raise TechnicalError('world wide autocompletion service not available') response = autocomplete.get(args, instances=available_instances) return response, 200
def get(self, region=None, lon=None, lat=None): args = self.parsers["get"].parse_args() self._register_interpreted_parameters(args) size_q = len(args['q']) if size_q == 0: abort(400, message="Search word absent") if size_q > 1024: abort( 413, message="Number of characters allowed for the search is 1024") if args['disable_geojson']: g.disable_geojson = True user = authentication.get_user(token=authentication.get_token(), abort_if_no_token=False) if args['shape'] is None and user and user.shape: args['shape'] = json.loads(user.shape) if not args.get("shape_scope[]") and user: args.update({"shape_scope[]": user.shape_scope}) if user and user.default_coord: if args['from'] is None: args['from'] = CoordFormat()(user.default_coord) else: if args['from'] == '': raise InvalidArguments( "if 'from' is provided it cannot be null") # If a region or coords are asked, we do the search according # to the region, else, we do a word wide search args["request_id"] = args.get('request_id', flask.request.id) if any([region, lon, lat]): self.region = i_manager.get_region(region, lon, lat) # when autocompletion is done on a specific coverage we want to filter on its shape if not args['shape']: instance = i_manager.instances.get(self.region) args['shape'] = build_instance_shape(instance) timezone.set_request_timezone(self.region) response = i_manager.dispatch(args, "places", instance_name=self.region) else: available_instances = get_all_available_instances(user) autocomplete = global_autocomplete.get('bragi') if not autocomplete: raise TechnicalError( 'world wide autocompletion service not available') response = autocomplete.get(args, instances=available_instances) return response, 200
def __init__(self, *args, **kwargs): ResourceUri.__init__(self, *args, **kwargs) parser_get = self.parsers["get"] parser_get.add_argument( "type[]", type=OptionValue(free_floatings_type), action="append", help="Type of free-floating objects to return", ) parser_get.add_argument("distance", type=int, default=500, help="Distance range of the query in meters") parser_get.add_argument("count", type=default_count_arg_type, default=10, help="Elements per page") self.parsers['get'].add_argument( "coord", type=CoordFormat(nullable=True), help="Coordinates longitude;latitude used to search " "the objects around this coordinate", )
def __init__(self, *args, **kwargs): ResourceUri.__init__(self, authentication=False, output_type_serializer=PlacesSerializer, *args, **kwargs) self.parsers["get"].add_argument("q", type=six.text_type, required=True, help="The data to search") self.parsers["get"].add_argument( "type[]", type=OptionValue(list(pb_type.keys())), action="append", default=["stop_area", "address", "poi", "administrative_region"], help="The type of data to search") self.parsers["get"].add_argument( "count", type=default_count_arg_type, default=10, help="The maximum number of places returned") self.parsers["get"].add_argument( "search_type", type=int, default=0, hidden=True, help="Type of search: firstletter or type error") self.parsers["get"].add_argument( "admin_uri[]", type=six.text_type, action="append", help="If filled, will restrain the search within the " "given admin uris") self.parsers["get"].add_argument("depth", type=depth_argument, default=1, help="The depth of objects") self.parsers["get"].add_argument( "_current_datetime", type=DateTimeFormat(), default=datetime.datetime.utcnow(), help="The datetime used to consider the state of the pt object.\n" "Default is the current date and it is used for debug.\n" "Note: it will mainly change the disruptions that concern " "the object. The timezone should be specified in the format, " "else we consider it as UTC", schema_type='datetime', hidden=True) self.parsers['get'].add_argument( "disable_geojson", type=BooleanType(), default=False, help="remove geojson from the response") self.parsers['get'].add_argument( "from", type=CoordFormat(nullable=True), help="Coordinates longitude;latitude used to prioritize " "the objects around this coordinate") self.parsers['get'].add_argument( "_autocomplete", type=six.text_type, hidden=True, help="name of the autocomplete service, used under the hood") self.parsers['get'].add_argument( 'shape', type=geojson_argument(), help='Geographical shape to limit the search.')