def create_app(): logging.basicConfig( level=logging.getLevelName(get_settings().LOG_LEVEL)) logging.debug("loading config") # do config app.config["__VERSION__"] = __version__ app.secret_key = get_settings().SECRET_KEY app.config["QUART_AUTH_COOKIE_SECURE"] = not get_settings().UNSECURE_LOGIN app.config["SEARCH_URL"] = get_settings().SEARCH_URL app.config["SHOW_PANEL_HEADERS"] = get_settings().SHOW_PANEL_HEADERS app.config["COMPACT_VIEW"] = get_settings().COMPACT_VIEW app.config["OPEN_TO_NEW_TAB"] = get_settings().OPEN_TO_NEW_TAB logging.debug("registering blueprints") # register blueprints app.register_blueprint(health_check.blueprint, url_prefix="/") app.register_blueprint(portal.blueprint, url_prefix="/") app.register_blueprint(login.blueprint, url_prefix="/auth") app.register_blueprint(admin.blueprint, url_prefix="/admin") logging.debug("registering tortoise-orm") # other setup register_tortoise( app, db_url=get_settings().DB_URI, modules={"models": [models]}, generate_schemas=True) logging.debug("init auth manager") auth_manager.init_app(app) logging.debug("created app") return app
def create_app(): logging.basicConfig(level=logging.getLevelName(get_settings().LOG_LEVEL)) app.config["SERVER_NAME"] = get_settings().SERVER_NAME register_tortoise(app, db_url=get_settings().DB_URI, modules={"models": [models]}, generate_schemas=True) return app
@app.route("/") async def list_all(): users, workers = await asyncio.gather(Users.all(), Workers.all()) return jsonify({ "users": [str(user) for user in users], "workers": [str(worker) for worker in workers] }) @app.route("/user") async def add_user(): user = await Users.create(status=choice(STATUSES)) # nosec return str(user) @app.route("/worker") async def add_worker(): worker = await Workers.create(status=choice(STATUSES)) # nosec return str(worker) register_tortoise( app, db_url="mysql://root:@127.0.0.1:3306/quart", modules={"models": ["models"]}, generate_schemas=False, ) if __name__ == "__main__": app.run(port=5000)
from config import DevelopmentConfig from tortoise.contrib.quart import register_tortoise from tortoise import Tortoise from quart import Quart app = Quart(__name__) app.config.from_object(DevelopmentConfig) register_tortoise(app, db_url=DevelopmentConfig.DATABASE_URI, modules={"models": ["app.models"]}, generate_schemas=True) from app.views import deep, neutral app.register_blueprint(deep) app.register_blueprint(neutral) if __name__ == '__main__': app.run()
js_assets = Bundle('js/cookie.js', 'js/index.js', filters='rjsmin', output='gen/bundled.js') css_assets = Bundle('css/index.css', filters='cssmin', output='gen/bundled.css') assets = Environment(app) assets.register('js_all', js_assets) assets.register('css_all', css_assets) # Minify HTML and any inline JS or CSS Minify(app, js=True) # gzip responses Compress(app) app.url_map.converters['list'] = ListConverter from . import filters from . import views register_tortoise( app, db_url=DB_URL, modules={'models': ['ordering.models']}, generate_schemas=DEBUG, )