def create_app(): app = Flask(__name__) app.config.from_object(conf) with Path(__file__).parent.parent as root_dir: database_file = "sqlite:///{}".format( os.path.join(root_dir, 'db.sqlite')) print('<DB FILE : {}>'.format(database_file)) app.config["SQLALCHEMY_DATABASE_URI"] = database_file db.init_app(app) migrate.init_app(app, db) app.register_blueprint(main_bp, url_prefix="/") admin = Admin(app, name=app.config["APP_NAME"], template_mode='bootstrap3') from app.models import TerritoryUnit, PositionType, Person, Recipient, RecipientAdmin, PersonAdmin, ContractType, \ TeamsList admin.add_link(MenuLink(name='Site publique', category='', url='/')) admin.add_view(PersonAdmin(Person, db.session, name='Personnes déclarées')) admin.add_view(ModelView(TerritoryUnit, db.session, name='Délégations')) admin.add_view(ModelView(ContractType, db.session, name='Contrats')) admin.add_view(ModelView(PositionType, db.session, name='Postes')) admin.add_view(ModelView(TeamsList, db.session, name='Listes teams')) admin.add_view(RecipientAdmin(Recipient, db.session, name='Destinataires')) with app.app_context(): db.create_all() return app
def client(app): with app.app_context(): database.create_all() c = app.test_client() setattr(c, 'db', database) # Mocking library functions requests.post = c.post werkzeug.wrappers.BaseResponse.json = lambda self, **kwargs: json.loads( self.data.decode()) return c
def create_app(testing_config=None) -> Flask: app = Flask(__name__) CORS(app) # load config env = os.environ.get('FLASK_ENV') if testing_config is None: if env == 'development': app.config.from_object(DevelopmentConfig) else: app.config.from_object(ProductionConfig) else: app.config.from_object(testing_config) # initialize database db.init_app(app) register_models() # initialize gpg gpg.init_app(app) # initialize redis blacklist if isinstance(app.config.get('BLACKLIST'), RedisBlacklist): app.config.get('BLACKLIST').blacklist.init_app(app) with app.app_context(): # create tables db.create_all() # register resources register_resource(app, AuthResource, 'auth_api', '/api/auth', get=False, put=False, delete=False) register_resource(app, RefreshResource, 'refresh_api', '/api/auth/refresh', pk='token', pk_type='string', get=False, get_all=False, put=False) register_resource(app, RoleResource, 'role_api', '/api/roles', pk='name', pk_type='string') register_resource(app, UserResource, 'user_api', '/api/users', pk='uuid', pk_type='string') register_resource(app, VerificationResource, 'verify_mail_api', '/api/users/verify', pk='token', pk_type='string', get=False, get_all=False, post=False, delete=False) register_resource(app, ResetResource, 'password_reset_api', '/api/reset', pk='token', pk_type='string', get=False, get_all=False, delete=False) register_resource(app, TOTPResource, 'two_factor_api', '/api/users/2fa', pk=None, get=False, put=False) register_resource(app, UploadResource, 'upload_api', '/api/upload', pk='uuid', pk_type='string', get_all=False, put=False, delete=False) # register views app.register_blueprint(default) app.register_blueprint(admin) app.register_blueprint(auth) return app
def migrate(): db.session.close() db.drop_all() db.create_all()
def create_db(): db.create_all()
def create(): db.create_all() print('create ok!')