def prime_database(): """Prime database with some fake data.""" init_webapp() # Initialize Flask-SQLAlchemy db.app = app db.init_app(app) db.create_all()
def runserver(*args, **kwargs): """Override default `runserver` to init webapp before running.""" app = init_webapp() # TODO(sholsapp): parameterize this, but don't clobber the *args, **kwargs # space, because it's annoying to have to pass these in to the `run` method. config = ConfigObj('config/sample.config', configspec='config/sample.configspec') app.config_obj = config app.run(*args, **kwargs)
def runserver(*args, **kwargs): """Override default `runserver` to init webapp before running.""" app = init_webapp() # TODO(sholsapp): parameterize this, but don't clobber the *args, **kwargs # space, because it's annoying to have to pass these in to the `run` method. config = ConfigObj('config/sample.config', configspec='config/sample.configspec') app.config_obj = config app.run(*args, **kwargs)
def prime_database(): """Prime database with some fake data.""" init_webapp() users = [ User(email='*****@*****.**', password='******', active=True, confirmed_at=datetime.datetime.utcnow()), ] for u in users: db.session.add(u) db.session.commit() employees = [ Employee('Bill', 'Lumbergh', 'Boss', '100000'), Employee('Peter', 'Gibbons', 'Employee', '50000'), Employee('Michael', 'Bolton', 'Employee', '50000'), Employee('Samir', 'Nagheenanajar', 'Employee', '50000'), Employee('Milton', 'Waddams', 'Employee', '0'), ] for e in employees: db.session.add(e) db.session.commit()
def prime_database(): """Prime database with some fake data.""" init_webapp() users = [ User(email='*****@*****.**', password='******', active=True, confirmed_at=datetime.datetime.utcnow()), ] for u in users: db.session.add(u) db.session.commit() employees = [ Employee('Bill', 'Lumbergh', 'Boss', '100000'), Employee('Peter', 'Gibbons', 'Employee', '50000'), Employee('Michael', 'Bolton', 'Employee', '50000'), Employee('Samir', 'Nagheenanajar', 'Employee', '50000'), Employee('Milton', 'Waddams', 'Employee', '0'), ] for e in employees: db.session.add(e) db.session.commit()
def app(request): app = Flask(__name__) app.config['SERVER_NAME'] = 'localhost' app = init_webapp(test=True) ctx = app.app_context() ctx.push() def teardown(): ctx.pop() request.addfinalizer(teardown) return app
def start_webapp(config): """Entry point to start web application. Call this function from a wrapper to initialize and start the web application. Configure the application using the process environment. Configurable attributes include: - HOST - PORT """ app = init_webapp(config) app.run( host=os.environ.get('HOST', config['webapp']['host']), port=os.environ.get('PORT', config['webapp']['port']), )
def runserver(host="127.0.0.1", port="5000"): """Override default `runserver` to init webapp before running.""" app = init_webapp() config = ConfigObj('config/sample.config', configspec='config/sample.configspec') app.config_obj = config app.run(host=host, port=int(port))
def post_fork(server, worker): init_webapp(server.app.configobj)
# add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata from flaskskeleton.model import db target_metadata = db.metadata # other values from the config, defined by the needs of env.py, # can be acquired: # my_important_option = config.get_main_option("my_important_option") # ... etc. # Set the databases URI the same way that the application does it. from flaskskeleton import init_webapp, app init_webapp() alembic_config = config.get_section(config.config_ini_section) config.set_main_option('sqlalchemy.url', app.config['SQLALCHEMY_DATABASE_URI']) alembic_config['sqlalchemy.url'] = app.config['SQLALCHEMY_DATABASE_URI'] def run_migrations_offline(): """Run migrations in 'offline' mode. This configures the context with just a URL and not an Engine, though an Engine is acceptable here as well. By skipping the Engine creation we don't even need a DBAPI to be available. Calls to context.execute() here emit the given string to the script output.