Exemplo n.º 1
0
def prime_database():
    """Prime database with some fake data."""
    init_webapp()
    # Initialize Flask-SQLAlchemy
    db.app = app
    db.init_app(app)
    db.create_all()
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
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()
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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']),
    )
Exemplo n.º 8
0
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))
Exemplo n.º 9
0
def post_fork(server, worker):
    init_webapp(server.app.configobj)
Exemplo n.º 10
0
# 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.