| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 | 
from flask import requestfrom flask_login import current_userfrom flask_restful import Resourcefrom controllers.console import apifrom controllers.console.app import _get_appfrom controllers.console.setup import setup_requiredfrom controllers.console.wraps import account_initialization_requiredfrom events.app_event import app_model_config_was_updatedfrom extensions.ext_database import dbfrom libs.login import login_requiredfrom models.model import AppModelConfigfrom services.app_model_config_service import AppModelConfigServiceclass ModelConfigResource(Resource):    @setup_required    @login_required    @account_initialization_required    def post(self, app_id):        """Modify app model config"""        app_id = str(app_id)        app = _get_app(app_id)        # validate config        model_configuration = AppModelConfigService.validate_configuration(            tenant_id=current_user.current_tenant_id,            account=current_user,            config=request.json,            app_mode=app.mode        )        new_app_model_config = AppModelConfig(            app_id=app.id,        )        new_app_model_config = new_app_model_config.from_model_config_dict(model_configuration)        db.session.add(new_app_model_config)        db.session.flush()        app.app_model_config_id = new_app_model_config.id        db.session.commit()        app_model_config_was_updated.send(            app,            app_model_config=new_app_model_config        )        return {'result': 'success'}api.add_resource(ModelConfigResource, '/apps/<uuid:app_id>/model-config')
 |