def criar_api(): if not pessoa_dao.buscaCpf(formataCpf(request.json['cpf'])): score = defini_score() nova_pessoa = Pessoa( formataCpf(request.json['cpf']), request.json['nome'], formataValor(formataDecimal(request.json['renda'])), request.json['logradouro'], request.json['numero'], request.json['bairro'], score, gerar_credito(request.json['renda'], score)) pessoa_dao.salvar(nova_pessoa) return app.response_class(response=json.dumps( nova_pessoa, default=lambda o: o.__dict__, sort_keys=True, indent=2), status=201, mimetype='application/json') else: return app.response_class(response=json.dumps({ "Mensagem": "CPF já cadastrado!", "Status": "400" }), status=400, mimetype='application/json')
def deletar_api(cpf): try: pessoa_dao.deletar(cpf) return app.response_class(response=json.dumps({ "Mensagem": "Cadastro removido com sucesso", "Status": "200" }), status=200, mimetype='application/json') except Exception as e: return app.response_class(response=json.dumps(str(e)), status=400, mimetype='application/json')
def api_models(): distro = request.args.get("distro", "") release = request.args.get("release", "") model_search = request.args.get("model_search", "") if distro != "" and release != "" and model_search != "": return app.response_class( response=database.get_supported_models(model_search, distro, release), mimetype='application/json') else: return "[]", HTTPStatus.BAD_REQUEST
def api_default_packages(): data = [] distro = request.args.get("distro", "") release = request.args.get("release", "") target = request.args.get("target", "") subtarget = request.args.get("subtarget", "") profile = request.args.get("profile", "") if distro != "" and release != "" and target != "" and subtarget != "" and profile != "": return app.response_class( response=database.get_image_packages(distro, release, target, subtarget, profile, as_json=True), mimetype='application/json') else: return "[]", HTTPStatus.BAD_REQUEST
def send_glyph(): prediction_font = db.session.query(Font).filter( Font.name == "Predictions").all()[-1] #Get the most recent predictions glyph_data = prediction_font.glyphs response = app.response_class(response=json.dumps( glyph_data, cls=recursive_alchemy_encoder(True, [ 'name', 'unicode', 'advance_width', 'contours', 'orientation', 'strokes', 'order', 'type', 'point', 'x', 'y' ]), check_circular=False), status=200, mimetype='application/json') return response
def get(self, run_id, attachment_id): if not check_access(path=f"/run/{str(run_id)}", method="GET"): abort(403) return run = Run.query.get(run_id) if not run or run.is_deleted: abort(404) return attachment = Attachment.query.get(attachment_id) if not attachment or attachment.is_deleted: abort(404) return return app.response_class( attachment.data, mimetype=attachment.mimetype if attachment.mimetype else 'application/octet-stream')
def api_releases(): distro = request.args.get("distro", "") return app.response_class( response=database.get_supported_releases(distro), mimetype='application/json')
def api_distros(): return app.response_class( response=database.get_supported_distros(), mimetype='application/json')
def api_manifest(manifest_hash): return app.response_class( response=database.get_manifest_info(manifest_hash, json=True), mimetype='application/json')
def api_image(image_hash): return app.response_class( response=database.get_image_info(image_hash, json=True) , mimetype='application/json')
def mime_json(response): return app.response_class( response=response, mimetype='application/json')