def process_state(request):
    """Procesa una consulta de tipo GET para normalizar provincias.

    Args:
        request (flask.Request): Objeto con información de la consulta HTTP.

    Returns:
        Resultado de la consulta como objecto flask.Response.
    """
    valid_rule, format_request, error = parser.get_url_rule(request)
    if not valid_rule:
        return parser.get_response_for_invalid(request, message=error)
    valid_request, error = parser.validate_params(request, STATES)
    if not valid_request:
        return parser.get_response_for_invalid(request, message=error)

    state_id = request.args.get(ID)
    name = request.args.get(NAME)
    max = request.args.get(MAX) or 24
    order = request.args.get(ORDER)
    fields = parser.get_fields(request.args.get(FIELDS))
    matches = data.query_entity(STATES,
                                entity_id=state_id,
                                name=name,
                                order=order,
                                fields=fields,
                                max=max)
    return parser.get_response({STATES: matches}, format_request)
def process_street(request):
    """Procesa una consulta de tipo GET para normalizar calles.

    Args:
        request (flask.Request): Objeto con información de la consulta HTTP.

    Returns:
        Resultado de la consulta como objecto flask.Response.
    """
    valid_request, error = parser.validate_params(request, STREETS)
    if not valid_request:
        return parser.get_response_for_invalid(request, message=error)

    name = request.args.get(NAME)
    locality = request.args.get(LOCALITY)
    department = request.args.get(DEPT)
    state = request.args.get(STATE)
    road_type = request.args.get(ROAD_TYPE)
    max = request.args.get(MAX)
    fields = parser.get_fields(request.args.get(FIELDS))

    matches = data.query_streets(name, locality, department, state, road_type,
                                 max, fields)
    for street in matches:
        street.pop(GEOM, None)

    return parser.get_response({STREETS: matches})
def process_department(request):
    """Procesa una consulta de tipo GET para normalizar departamentos.

    Args:
        request (flask.Request): Objeto con información de la consulta HTTP.

    Returns:
        Resultado de la consulta como objecto flask.Response.
    """
    valid_rule, format_request, error = parser.get_url_rule(request)
    if not valid_rule:
        return parser.get_response_for_invalid(request, message=error)
    valid_request, error = parser.validate_params(request, DEPARTMENTS)
    if not valid_request:
        return parser.get_response_for_invalid(request, message=error)

    dept_id = request.args.get(ID)
    name = request.args.get(NAME)
    state = request.args.get(STATE)
    max = request.args.get(MAX) or format_request['max']
    order = request.args.get(ORDER)
    fields = parser.get_fields(request.args.get(FIELDS))
    flatten = FLATTEN in request.args or format_request['convert']

    matches = data.query_entity(DEPARTMENTS,
                                entity_id=dept_id,
                                name=name,
                                state=state,
                                flatten=flatten,
                                order=order,
                                fields=fields,
                                max=max)

    return parser.get_response({DEPARTMENTS: matches}, format_request)
Example #4
0
def process_locality(request):
    """Procesa una consulta de tipo GET para normalizar localidades.

    Args:
        request (flask.Request): Objeto con información de la consulta HTTP.

    Returns:
        Resultado de la consulta como objeto flask.Response.
    """
    valid_rule, format_request, error = parser.get_url_rule(request)
    if not valid_rule:
        return parser.get_response_for_invalid(request, message=error)
    valid_request, error = parser.validate_params(request, SETTLEMENTS)
    if not valid_request:
        return parser.get_response_for_invalid(request, message=error)

    locality_id = request.args.get(ID)
    name = request.args.get(NAME)
    state = request.args.get(STATE)
    department = request.args.get(DEPT)
    municipality = request.args.get(MUN)
    exact = EXACT in request.args
    order = request.args.get(ORDER)
    fields = parser.get_fields(request.args.get(FIELDS))
    flatten = FLATTEN in request.args or format_request['convert']
    max = request.args.get(MAX) or format_request['max']

    matches = data.query_entity(SETTLEMENTS,
                                entity_id=locality_id,
                                name=name,
                                municipality=municipality,
                                department=department,
                                state=state,
                                max=max,
                                order=order,
                                fields=fields,
                                flatten=flatten,
                                exact=exact)

    return parser.get_response({LOCALITIES: matches}, format_request)