def create_app(settings_override=None): """Returns the main application instance""" app = factory.create_app(__name__, __path__, settings_override) # Init assets assets.init_app(app) # Set static folder app.static_folder = STATIC_FOLDER if app.debug: app.static_folder = STATIC_FOLDER_DEBUG # Init debugToolbar DebugToolbarExtension(app) app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension') app.json_encoder = JSONEncoder for e in [500, 404]: try: app.errorhandler(e)(handle_error) except: pass if not app.debug: for e in [500, 404]: app.errorhandler(e)(handle_error) return app
def app(): """ application fixture :return: """ application = create_app() yield application
def create_app(settings_override=None): """Returns the main application instance""" app = factory.create_app(__name__, __path__, settings_override) # Set static folder app.static_folder = STATIC_FOLDER if app.debug: app.static_folder = STATIC_FOLDER_DEBUG # Init assets assets.init_app(app) app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension') app.json_encoder = JSONEncoder for e in [500, 404]: try: app.errorhandler(e)(handle_error) except: pass if not app.debug: for e in [500, 404]: app.errorhandler(e)(handle_error) @app.context_processor def inject_default(): lang = babel.app.config['BABEL_DEFAULT_LOCALE'] this_year = datetime.now().year return dict(lang=lang, this_year=this_year, static_guid=STATIC_GUID) return app
def create_app(settings_override=None): """Returns the main application instance""" app = factory.create_app(__name__, __path__, settings_override) # Set static folder app.static_folder = STATIC_FOLDER if app.debug: app.static_folder = STATIC_FOLDER_DEBUG # Init assets assets.init_app(app) app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension') app.json_encoder = JSONEncoder for e in [500, 404]: try: app.errorhandler(e)(handle_error) except: pass if not app.debug: for e in [500, 404]: app.errorhandler(e)(handle_error) @app.context_processor def inject_default(): lang = babel.app.config['BABEL_DEFAULT_LOCALE'] this_year = datetime.now().year return dict(lang=lang, this_year=this_year, static_guid=STATIC_GUID) return app
def setup(self): app = create_app('application.config.TestConfig') self.client = app.test_client() user_datastore.create_user(email='*****@*****.**', password='******') user_datastore.create_user(email='*****@*****.**', password='******')
def setup(self): app = create_app('application.config.TestConfig') self.client = app.test_client() user_datastore.create_user(email='*****@*****.**', password='******') user_datastore.create_user(email='*****@*****.**', password='******')
def single_use_app(): """ A function-scoped app fixture. This should only be used for testing the static site building process, as that process requires an app which has not yet handled any requests. This is the case for all management commands, which are run on Heroku in unroutable, single-use instances of our app. """ _app = create_app(TestConfig) return _app
def app(request): app = create_app('config.TestConfig') ctx = app.test_request_context() ctx.push() def teardown(): ctx.pop() request.addfinalizer(teardown) return app
def db_migration(): print("Doing db setup") app = create_app(TestConfig) Migrate(app, app_db) Manager(app_db, MigrateCommand) ALEMBIC_CONFIG = os.path.join(os.path.dirname(__file__), "../migrations/alembic.ini") config = Config(ALEMBIC_CONFIG) config.set_main_option("script_location", "migrations") with app.app_context(): upgrade(config, "head") print("Done db setup")
def app(request): """Session-wide test `Flask` application.""" app = create_app('config.TestConfig') # Establish an application context before running the tests. ctx = app.app_context() ctx.push() def teardown(): ctx.pop() request.addfinalizer(teardown) return app
def create_app(settings_override=None, register_security_blueprint=False): """Returns the Service API application instance :param settings_override: :param register_security_blueprint: """ app = factory.create_app(__name__, __path__, settings_override, register_security_blueprint=register_security_blueprint) # init_whoosh_index() # Set the default JSON encoder app.json_encoder = JSONEncoder # Register custom error handlers app.errorhandler(ApplicationError)(on_application_error) app.errorhandler(404)(on_404) return app
def create_app(settings_override=None, register_security_blueprint=False): """Returns the Service API application instance :param settings_override: :param register_security_blueprint: """ app = factory.create_app( __name__, __path__, settings_override, register_security_blueprint=register_security_blueprint) # Set the default JSON encoder app.json_encoder = JSONEncoder # Register custom error handlers app.errorhandler(ApplicationError)(on_application_error) app.errorhandler(404)(on_404) return app
def setup(self): app = create_app('application.config.TestConfig') self.client = app.test_client() user = user_datastore.create_user(email='*****@*****.**', password='******') email_domain = app.config.get('EMAIL_DOMAIN') user.inbox_email = "someone@%s" % email_domain user.save() assert user.inbox_email == '*****@*****.**' user_datastore.create_user(email='*****@*****.**', password='******') self.client.post('/login', data={ 'email': '*****@*****.**', 'password': '******' }, follow_redirects=True)
def setup(self): app = create_app('application.config.TestConfig') self.client = app.test_client() user = user_datastore.create_user( email='*****@*****.**', password='******') email_domain = app.config.get('EMAIL_DOMAIN') user.inbox_email = "someone@%s" % email_domain user.save() assert user.inbox_email == '*****@*****.**' user_datastore.create_user( email='*****@*****.**', password='******') self.client.post( '/login', data={ 'email': '*****@*****.**', 'password': '******'}, follow_redirects=True)
import os from application.factory import create_app app = create_app(os.environ['SETTINGS'])
from application.models import ( Entry, Link, LogEntry, Role, Tag, User ) from application.competency.models import ( Behaviour, Competency, CompetencyCluster, Level ) app = create_app(os.environ.get('SETTINGS', 'application.config.Config')) app.debug = True port = os.environ.get('PORT', 8000) manager = Manager(app) manager.add_command('server', Server(host="0.0.0.0", port=port)) from application.extensions import user_datastore class CreateUser(Command): """ Creates a user for this app """ def run(self):
# Import logging library. # More about loguru: https://loguru.readthedocs.io/en/stable/overview.html from loguru import logger # Remove default handler. logger.remove() # Console logger. logger.add( sink=sys.stderr, level=os.environ.get("LOG_LEVEL", "INFO"), format="|{time}| |{process}| |{level}| |{name}:{function}:{line}| {message}" ) from elasticsearch import Elasticsearch es = Elasticsearch(os.getenv("ELASTICSEARCH")) from googletrans import Translator translator = Translator() # Create application instance. from application.factory import create_app app = create_app() from application.utils.before_first_request_funcs import init_db init_db()
data_source.frequency_of_release_other, DataSource.purpose == data_source.purpose, ).with_entities(DataSource.id).all()) print(f"Data source #{data_source.id}:") if other_identical_data_sources: for other_identical_data_source in other_identical_data_sources: print( f" Absorbed #{other_identical_data_source.id}" ) count += 1 data_source.merge(other_identical_data_sources) db.session.commit() except Exception as e: print(e) db.session.rollback() finally: db.session.close() print(f"Finished. Merged {count} duplicate data sources.") if __name__ == "__main__": app = create_app(Config()) merge_identical_duplicate_data_sources(app)
from application import factory from application import celery from tasks import columns_name if __name__ == '__main__': flask_app = factory.create_app(celery=celery) flask_app.run(host='0.0.0.0')
def app(request): _app = create_app(TestConfig) return _app
from application.factory import create_app import application app = create_app(celery=application.celery) if __name__ == "__main__": app.run()
import os from application.factory import create_app app = create_app(os.environ['SETTINGS'])
#!/usr/bin/env python # encoding: utf-8 from flask_script import Manager from flask_migrate import Migrate, MigrateCommand from application.factory import create_app from application.core import db app = create_app() manager = Manager(app) migrate = Migrate(app, db) manager.add_command('db', MigrateCommand) @manager.option('-h', '--host', dest="host", default="0.0.0.0", type=str) @manager.option('-p', '--port', dest="port", default=8080, type=int) def run(host, port): from wsgi import application from werkzeug.serving import run_simple run_simple(host, port, application, use_reloader=True, use_debugger=True) if __name__ == '__main__': manager.run()
import os from flask_migrate import Migrate from application.factory import create_app from application.extensions import db from application.models import * app = create_app(os.getenv('FLASK_CONFIG') or 'config.DevelopmentConfig') migrate = Migrate(app, db) @app.shell_context_processor def make_shell_context(): return dict(app=app, db=db)
# -*- coding: utf-8 -*- from application.factory import create_app app = create_app(__name__)
#! /usr/bin/env python import os from flask_script import Manager, Server from application.factory import create_app from application.config import Config, DevConfig env = os.environ.get('ENVIRONMENT', 'DEV') app = create_app(DevConfig) manager = Manager(app) manager.add_command("server", Server()) if __name__ == '__main__': manager.run()
import os from application.factory import create_app app = create_app(os.environ.get('SETTINGS', 'application.config.Config'))