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)
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_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)