コード例 #1
0
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
コード例 #2
0
ファイル: conftest.py プロジェクト: wei-hai/mono
def app():
    """
    application fixture
    :return:
    """
    application = create_app()
    yield application
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
    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='******')
コード例 #6
0
    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='******')
コード例 #7
0
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
コード例 #8
0
def app(request):
    app = create_app('config.TestConfig')

    ctx = app.test_request_context()
    ctx.push()

    def teardown():
        ctx.pop()

    request.addfinalizer(teardown)
    return app
コード例 #9
0
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")
コード例 #10
0
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
コード例 #11
0
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
コード例 #12
0
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
コード例 #13
0
    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)
コード例 #14
0
    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)
コード例 #15
0
import os
from application.factory import create_app
app = create_app(os.environ['SETTINGS'])
コード例 #16
0
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):
コード例 #17
0
# 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()
コード例 #18
0
                        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)
コード例 #19
0
ファイル: app.py プロジェクト: algow/profil_satker
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')
コード例 #20
0
def app(request):
    _app = create_app(TestConfig)

    return _app
コード例 #21
0
ファイル: run.py プロジェクト: dev-jey/flask-telegram-bot
from application.factory import create_app
import application

app = create_app(celery=application.celery)

if __name__ == "__main__":
    app.run()
コード例 #22
0
import os

from application.factory import create_app
app = create_app(os.environ['SETTINGS'])
コード例 #23
0
ファイル: manage.py プロジェクト: wlwio/flask-skeleton
#!/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()
コード例 #24
0
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)
コード例 #25
0
# -*- coding: utf-8 -*-

from application.factory import create_app

app = create_app(__name__)
コード例 #26
0
ファイル: manage.py プロジェクト: thomasridd/buzz-heroku
#! /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()
コード例 #27
0
import os

from application.factory import create_app
app = create_app(os.environ.get('SETTINGS', 'application.config.Config'))