Example #1
0
 def _in_app_func(*args, **kw):
     app = create_app()
     ac = app.app_context()
     try:
         ac.push()
         kw['app'] = app
         func(*args, **kw)
     finally:
         ac.pop()
Example #2
0
 def _in_session_request_func(*args, **kw):
     request_ctx = None
     app = create_app()
     ac = app.app_context()
     try:
         ac.push()
         request_ctx = app.test_request_context('/')
         request_ctx.push()
         kw['app'] = app
         func(*args, **kw)
     finally:
         if request_ctx:
             request_ctx.pop()
         ac.pop()
Example #3
0
from boac.factory import create_app

# When running under WSGI, system environment variables are not automatically made available to Python code, and
# an app restart will result in configurations being lost. We work around this with an explicit load from the shell
# environment, sourcing from the Elastic Beanstalk-provided /opt/python/current/env file if available.
if __name__.startswith('_mod_wsgi'):
    command = [
        'bash', '-c', '{ source /opt/python/current/env || true; } && env'
    ]
    shell_environment = subprocess.Popen(command, stdout=subprocess.PIPE)
    for line in shell_environment.stdout:
        key, _, value = line.decode('utf-8').rstrip().partition('=')
        os.environ[key] = value

application = create_app()


@application.cli.command()
def initdb():
    from boac.models import development_db
    development_db.load()


@application.cli.command()
def load_external_data():
    from boac.api import cache_utils
    cache_utils.load_current_term()


@application.cli.command()
Example #4
0
    ``runfile('consoler.py')``
* Save
* Click on "Python Console"
* Click the bug icon to start a debugging session:

>>> from boac.models.authorized_user import AuthorizedUser
>>> rows = AuthorizedUser.query.all()
>>> pp(rows)
[
    <AuthorizedUser 2040,
                        is_admin=True,
                        is_advisor=False,
                        is_director=False,
                        updated=2018-01-12 11:02:35.536022,
                        created=2018-01-12 11:02:35.536011>
                    , ...

"""

from boac.factory import create_app
from pprintpp import pprint as pp  # noqa

app = create_app()
ac = app.app_context()
ac.push()

print(
    'You are now in a Flask app context. To run normal app teardown processes, type:'
)
print('   ac.pop()')