Пример #1
1
    def create_app(environment=None):
        """
        Create an app instance
        """
        app = Flask("core")

        # Allow CORS for all domains on all routes
        CORS(app)

        # Config app for environment
        if not environment:
            environment = os.environ.get("BACKEND_ENVIRONMENT", "Dev")

        app.config.from_object("core.api.settings.%s" % environment)

        # convert exceptions to JSON
        def make_json_error(ex):
            response = jsonify(message=str(ex))
            response.status_code = ex.code if isinstance(ex, HTTPException) else 500

            return response

        for code in default_exceptions.items():
            app.error_handler_spec[None][code] = make_json_error

        from core.api.views.endpoints import api

        app.register_module(api)

        API.app = app
Пример #2
1
def get_app(settings_module="awsmanager.settings"):
    app = Flask(__name__)
    app.config.from_object(settings_module)

    app.register_module(frontend)

    return app
Пример #3
1
def create_app(environment=None):
    """
    Create an app instance
    """
    app = Flask("backend")
    app.url_map.converters["ObjectId"] = BSONObjectIdConverter

    # Config app for environment
    if not environment:
        environment = os.environ.get("BACKEND_ENVIRONMENT", "Local")

    app.config.from_object("backend.backend.settings.%s" % environment)

    # convert exceptions to JSON
    def make_json_error(ex):
        response = jsonify(message=str(ex))
        response.status_code = ex.code if isinstance(ex, HTTPException) else 500
        return response

    for code in default_exceptions.iterkeys():
        app.error_handler_spec[None][code] = make_json_error

    from backend.backend.views.api import api

    app.register_module(api)

    # initialize modules
    admin.init_app(app)
    db.init_app(app)
    login_manager.setup_app(app)
    mail.init_app(app)

    return app
Пример #4
1
def create_app(database):
    global app

    # create our little application :)
    app = Flask(__name__)
    app.debug = True
    app.config.from_object(__name__)
    app.secret_key = "^]CUCqFL6;wVz-w4%#ZYKTIB]kWT+3rfAq@_}(p;r%Mjq6umt9\>8-.){.u!uA*"

    # db import
    from libs.db import init_connection

    # db setup
    init_connection(database)

    # presenters
    from presenters.listing import listing
    from presenters.doc import doc

    # register modules
    app.register_module(listing)
    app.register_module(doc)

    # template filters
    @app.template_filter("test_format")
    def test_format(input):
        return input[::-1]

    return app
Пример #5
1
def create_app():
    app = Flask(__name__)
    app.debug = config.IS_DEBUG
    app.url_map.converters["re"] = helpers.RegexConverter
    app.register_module(basemod)
    configure_handlers(app)

    return app
Пример #6
1
def create_app():
    app = Flask(__name__)
    app.register_module(pkgmod.mod)
    app.register_module(modmod.mod)

    genshi = Genshi(app)

    return app
Пример #7
0
def create_app():
    """Create your application."""
    app = Flask(__name__)
    app.config.from_object(settings)
    app.register_module(views)
    db.app = app
    db.init_app(app)
    db.create_all()
    return app
Пример #8
0
def create_app():
    """
    Create your application. Files outside the app directory can import
    this function and use it to recreate your application -- both
    bootstrap.py and the `tests` directory do this.
    """
    app = Flask(__name__)
    app.config.from_object(settings)
    app.register_module(views)
    return app
Пример #9
0
def create_app(app_name=APP_NAME):
    app = Flask(__name__)
    app.config.from_object(__name__)

    cur = os.path.abspath(__file__)
    sys.path.append(os.path.dirname(cur) + "/apps")
    for a in APPS:
        app.register_module(__import__("%s.views" % a).module)

    return app
Пример #10
0
 def setUp(self):
     app = Flask(__name__)
     app.config["SECRET_KEY"] = "blahblah"
     app.config["ODESK_KEY"] = "56adf4b66aaf61444a77796c17c0da53"
     app.config["ODESK_SECRET"] = "e5864a0bcbed2085"
     app.register_module(odesk, url_prefix="/odesk")
     ctx = app.test_request_context()
     ctx.push()
     self.app = app
     self.tc = self.app.test_client()
Пример #11
0
def Mojology(config_file=None, config_object=None):
    app = Flask(__name__)
    app.config.from_object("mojology.default_config")
    app.config.from_envvar("MOJOLOGY_SETTINGS", True)

    if config_file:
        app.config.from_pyfile(config_file)
    if config_object:
        app.config.from_object(config_object)

    app.register_module(browser)
    app.register_module(statsm, url_prefix="/stats")

    def version():
        try:
            import os
            from dulwich.repo import Repo

            repo = Repo(os.path.join(os.path.dirname(__file__), ".."))

            return repo.refs["refs/heads/master"]
        except:
            return None

    @app.template_filter("datetime")
    def datetimeformat(value, format="%Y-%m-%d %H:%M:%S"):
        return datetime.datetime.fromtimestamp(float(value)).strftime(format)

    @app.errorhandler(404)
    def handler_404(error):
        return render_template("http_error.html", error=error), 404

    @app.errorhandler(500)
    def handler_500(error):
        return render_template("http_error.html", error=error), 500

    @app.errorhandler(503)
    def handler_503(error):
        return render_template("http_error.html", error=error), 503

    @app.route("/about")
    @app.route("/about/")
    @templated()
    def about():
        return None

    @app.route("/")
    def dashboard():
        redirect(url_for("browser.index"))

    app.version = version()
    return app
def make_app():
    app = Flask(__name__)

    from admin import admin
    from frontend import frontend

    config = app_config()
    app.config.from_object(config)

    app.register_module(frontend)
    app.register_module(admin)

    return app
Пример #13
0
def create_app(database_uri, debug=False):
    app = Flask(__name__)
    app.debug = debug

    # set up your database
    app.engine = create_engine(database_uri)

    # add your modules
    app.register_module(frontend)

    # other setup tasks

    return app
Пример #14
0
def create_app(config_filename):
    app = Flask(__name__)
    app.config.from_pyfile(config_filename)

    @app.before_request
    def auth():
        g.user = session.get("user_id", None)

    from .views import frontend

    app.register_module(frontend)

    return app
Пример #15
0
def make_app(config=None):
    app = Flask(__name__)
    if config:
        app.config.from_object(config)

    try:
        app.config.from_envvar(ENVVAR_NAME)
    except RuntimeError:
        print ENVVAR_NAME, "not set. Using default configuration."

    app.register_module(httpqueue.views.queue.view, url_prefix="/queue")
    httpqueue.views.queue.view.logger = app.logger
    httpqueue.model.init_model(app)
    return app
Пример #16
0
def create_app():
    app = Flask(__name__)

    if DEV:
        app.config.from_object("settings.Dev")
    else:
        app.config.from_object("settings.Prod")

    sys.path.append(os.path.join(BASE_DIR, APPS_DIR))

    for module_name in APPS:
        app.register_module(load_module(module_name))

    return app
Пример #17
0
def create_app():
    """
    Create your application. Files outside the app directory can import
    this function and use it to recreate your application -- both
    bootstrap.py and the `tests` directory do this.
    """
    app = Flask(__name__)
    app.config.from_object(settings)
    app.register_module(views)
    app.jinja_env.filters["format_date"] = format_date
    app.jinja_env.filters["pygments_markdown"] = pygments_markdown
    app.jinja_env.filters["link_tags"] = link_tags
    app.jinja_env.filters["get_comment_count"] = get_comment_count
    return app
Пример #18
0
def create_app(wof_inst, soap_service_url=None):
    app = Flask(__name__)

    app.config.from_object(config.Config)
    app.wof_inst = wof_inst
    if not "SOAP_SERVICE_URL" in app.config and soap_service_url:
        app.config["SOAP_SERVICE_URL"] = soap_service_url

    if USE_BLUEPRINTS:
        app.register_blueprint(rest)
        app.register_blueprint(wsdl)
    else:
        app.register_module(rest)
        app.register_module(wsdl)

    return app
Пример #19
0
def create_app(database, drop=False):
    # create our little application :)
    app = Flask(__name__)
    app.debug = True
    app.config.from_object(__name__)
    app.secret_key = "DtJe0TW8ZQqLWT7UVE7alBN6vxxI6xBCDjVbcgY3"

    # db import
    from db import init_connection, table_drop

    # db setup
    init_connection(database)
    # db cleanup?
    if drop:
        table_drop("goals")

    # presenters
    from presenters.goals import goals
    from presenters.cdn import cdn

    # register modules
    app.register_module(goals)
    app.register_module(cdn)

    # template filters
    @app.template_filter("timestamp_format")
    def timestamp_format(timestamp):
        return utils.timestamp_format(timestamp)

    @app.template_filter("timestamp_distance")
    def timestamp_distance(timestamp):
        r = (utils.timestamp_new() - timestamp) / 60 / 60 / 24
        if r > 0:
            if r > 1:
                return "".join([str(r), " days ago"])
            else:
                return "yesterday"
        elif r < 0:
            if r < -1:
                return "".join(["in ", str(abs(r)), " days"])
            else:
                return "tomorrow"
        else:
            return "today"

    return app
Пример #20
0
def init_app(defer_init_app=False):
    app = Flask(__name__)
    app.register_module(admin_module, url_prefix="/admin")
    if defer_init_app:
        freezer = Freezer()
    else:
        freezer = Freezer(app)

    @app.route("/")
    def index():
        return "Main index"

    @app.route("/page/<name>/")
    def page(name):
        return u"Hello\xa0World! " + name

    @app.route("/where_am_i/")
    def where_am_i():
        return url_for("where_am_i") + " " + url_for("where_am_i", _external=True)

    @app.route("/robots.txt")
    def robots_txt():
        content = "User-agent: *\nDisallow: /"
        return app.response_class(content, mimetype="text/plain")

    @app.route("/product_<int:product_id>/")
    def product(product_id):
        return "Product num %i" % product_id

    @freezer.register_generator
    def product():
        # endpoint, values
        yield "product", {"product_id": 0}
        # Just a `values` dict. The endpoint defaults to the name of the
        # generator function, just like with Flask views
        yield {"product_id": 1}
        # single string: url
        yield "/product_2/"

        yield "page", {"name": u"I løvë Unicode"}

    if defer_init_app:
        freezer.init_app(app)

    return app, freezer
Пример #21
0
def create_app():
    app = Flask(__name__)
    app.config.from_object("portal.settings")
    app.config["MONGOALCHEMY_DATABASE"] = "portal"

    from portal.models import db

    db.init_app(app)

    from portal.login import door

    app.register_module(door)

    from portal.users import portal

    app.register_module(portal)

    return app
Пример #22
0
def create_app(config=None):

    app = Flask(__name__)

    app.config.from_object("stutuz.configs")
    if config is not None:
        app.config.from_object(config)
    app.config.from_envvar("STUTUZ_CONFIG", silent=True)

    @app.context_processor
    def global_context():
        return dict(locale=get_locale(), Markup=Markup)  # Flask's seems to be superior to Genshi's

    handlers = NestedSetup(app.config.get("LOGBOOK_HANDLERS"))

    @app.before_request
    def push_handlers():
        handlers.push_thread()

    @app.after_request
    def pop_handlers(response):
        handlers.pop_thread()
        return response

    for extension in genshi, db:
        extension.init_app(app)

    babel = Babel(app)

    @babel.localeselector
    def best_locale():
        if "locale" in request.args:
            return request.args["locale"]
        return request.accept_languages.best_match(map(str, babel.list_translations()))

    for middleware in app.config.get("MIDDLEWARES", ()):
        app.wsgi_app = middleware(app.wsgi_app)

    app.url_map.converters.update(CONVERTERS)
    for url_prefix, module in MODULES:
        module = import_string(module).mod
        app.register_module(module, url_prefix=url_prefix)

    return app
Пример #23
0
def create_app():
    app = Flask(__name__)
    app.config.from_object("polipoly2.default_settings")
    app.config.from_envvar("POLIPOLY2_SETTINGS", silent=True)

    register_converters(app)

    init_engine(app.config["DATABASE_URI"])

    def shutdown_session(response):
        session.remove()
        return response

    app.after_request(shutdown_session)

    from polipoly2.views import views

    app.register_module(views)

    return app
Пример #24
0
def create_app(config=None):
    app = Flask(__name__)
    app.config.from_object(default_settings)

    app.config.from_envvar("SIMBLIN_SETTINGS", silent=True)

    if config:
        app.config.from_object(config)

    db.init_app(app)

    @app.context_processor
    def inject_static():
        """Make the static helper function available inside the templates"""
        return dict(static=static)

    app.register_module(admin)
    app.register_module(main)

    return app
Пример #25
0
def create_app(config=None):
    app = Flask(__name__)

    app.config.from_object(__name__)
    if config:
        app.config.from_object(config)

    # Configure logging here

    # Configure extensions

    # Error handlers

    if not app.debug:

        @app.errorhandler(404)
        def page_not_found(error):
            return render_template("404.html", error=error)

        @app.errorhandler(500)
        def server_error(error):
            return render_template("500.html", error=error)

    # Before and after handlers

    @app.before_request
    def before_request():
        pass

    @app.after_request
    def after_request(request):
        # Play with your request here
        return request

    # Register modules

    app.register_module(views.front, url_prefix="")

    return app
Пример #26
0
def create_app(configuration_file=None):
    app = Flask(__name__)
    app.plugins = []

    # cannot use namespace here, weak signals will disappear
    app.plugin_signals = {
        "plugin-loaded": Signal(),
        "page-loaded": Signal(),
        "special-loaded": Signal(),
        "page-preprocess": Signal(),
        "page-postmarkdown": Signal(),
        "page-treeprocess": Signal(),
        "page-postprocess": Signal(),
    }

    # load a default config, and from configuration file
    app.config.from_object(defaults)
    if configuration_file:
        app.config.from_pyfile(configuration_file)

    app.db = WikiDb(app.config["REPOSITORY_PATH"])
    app.cache = Cache(app)

    app.register_module(frontend)

    # load plugins
    for plugin_name in app.config["PLUGINS"]:
        import_name = "qwappplugin.%s" % plugin_name

        qwappplugin = __import__("qwappplugin.%s" % plugin_name)
        plugin_module = getattr(qwappplugin, plugin_name)
        app.logger.debug("loading plugin %s" % plugin_module.plugin.version_string)

        plugin_module.plugin.register_app(app)

    return app
Пример #27
0
def create():
    app = Flask(__name__)
    app.config.from_object("app.settings")

    # register view modules
    from app.controllers.frontend import frontend
    from app.controllers.companies import companies
    from app.controllers.accounts import accounts

    app.register_module(frontend)
    app.register_module(companies)
    app.register_module(accounts)

    return app
Пример #28
0
def create_app(config_filename):
    app = Flask(__name__)
    app.config.from_pyfile(config_filename)

    # register views
    from einfachjabber.apps.mainsite.views import mainsite
    from einfachjabber.apps.blog.views import blog
    from einfachjabber.apps.stats.views import stats

    app.register_module(mainsite)
    app.register_module(blog, url_prefix="/blog")
    app.register_module(stats, url_prefix="/stats")

    # initiate flask-extensions
    mail.init_app(app)
    db.setup(app)

    # template filter setup
    @app.template_filter("to_mdown")
    def to_mdown(s):
        return Markup(markdown(s))

    # set up logging
    if not app.debug:
        import logging
        from logging import FileHandler
        from logging.handlers import SMTPHandler

        mail_handler = SMTPHandler(
            app.config["MAIL_SERVER"],
            app.config["DEFAULT_MAIL_SENDER"],
            app.config["ADMINS"],
            "[einfachJabber.de] Failed",
            (app.config["MAIL_USERNAME"], app.config["MAIL_PASSWORD"]),
        )
        mail_handler.setLevel(logging.ERROR)
        app.logger.addHandler(mail_handler)
        file_handler = FileHandler(app.config["LOG_PATH"])
        file_handler.setLevel(logging.INFO)
        app.logger.addHandler(file_handler)

    @app.errorhandler(404)
    def not_found(e):
        """Handles 404s"""
        pagetitle = "404 - Seite nicht gefunden"
        return render_template("404.html", pagetitle=pagetitle), 404

    return app
Пример #29
0
def create_app():
    """
    Create your application. Files outside the app directory can import
    this function and use it to recreate your application -- both
    bootstrap.py and the `tests` directory do this.
    """
    app = Flask(__name__)
    app.config.from_object(settings)
    babel = Babel(app, configure_jinja=True)
    babel.localeselector(_localeselector)
    babel.timezoneselector(_timezoneselector)
    app.register_module(views)
    app.register_module(rpc)
    app.register_module(tasks)
    app.secret_key = settings.secret_key
    return app
Пример #30
0
def create_app(config):
    app = Flask(__name__)
    app.config.from_pyfile(os.path.abspath(config))
    from cadorsfeed.views.daily_report import daily_report
    from cadorsfeed.views.report import report
    from cadorsfeed.views.category import category
    from cadorsfeed.views.search import search
    from cadorsfeed.views.static import static

    app.register_module(daily_report)
    app.register_module(report)
    app.register_module(category)
    app.register_module(search)
    app.register_module(static)
    app.add_url_rule("/favicon.ico", "favicon", redirect_to="/static/favicon.ico")
    db.init_app(app)

    app.jinja_env.globals["modified_url_for"] = modified_url_for
    app.jinja_env.globals["config"] = app.config

    if app.config["PROXY_FIX"]:
        app.wsgi_app = ProxyFix(app.wsgi_app)

    return app