Rewrite to Quart web-framework, refactor code.

This commit is contained in:
dsc 2022-03-12 14:46:31 +02:00
parent 6b300fd304
commit 67f4c34604
39 changed files with 656 additions and 980 deletions

25
yellow/api.py Normal file
View file

@ -0,0 +1,25 @@
from quart import render_template, request, redirect, url_for, jsonify, Blueprint, abort, flash, send_from_directory, current_app
import settings
from yellow.models import User
bp_api = Blueprint('bp_api', __name__, url_prefix='/api')
@bp_api.get("/")
async def api_root():
return await render_template('api.html')
@bp_api.get('/user/')
async def api_all():
return jsonify([u.to_json(ignore_key='id') for u in User.select()])
@bp_api.get('/user/<path:needle>')
async def api_search(needle: str):
try:
return jsonify([u.to_json(ignore_key='id') for u in await User.search(needle)])
except Exception as ex:
current_app.logger.error(ex)
return jsonify([])