def __call__(cls,
                 flask_or_import_name,
                 projects=None,
                 project_name=None,
                 app_directory=None
                 ):
        """

        :param flask_or_import_name: Flask instance or import name -> __name__
        :param projects: dict of app and views to load. ie:
            {
                "main": [
                    "main",
                    "api"
                ]
            }
        :param project_name: name of the project. If empty, it will try to get
                             it from the app_env(). By default it is "main"
                             The app main is set as environment variable
                             ie: app=PROJECT_NAME:CONFIG -> app=main:production
        :param app_directory: the directory name relative to the current execution path
        :return:
        """
        if not app_directory:
            app_directory = "application"
        if not project_name:
            project_name = get_app_env()[0] or "main"

        app_env = get_env()

        app = flask_or_import_name \
            if isinstance(flask_or_import_name, Flask) \
            else Flask(flask_or_import_name)

        app.url_map.converters['regex'] = RegexConverter
        app.template_folder = "%s/templates" % app_directory
        app.static_folder = "%s/static" % app_directory

        # Load configs
        c = "%s.config.%s" % (app_directory, app_env)
        app.config.from_object(c)

        # Proxyfix
        # By default it will use PROXY FIX
        # To by pass it, or to use your own, set config
        # USE_PROXY_FIX = False
        if app.config.get("USE_PROXY_FIX", True):
            app.wsgi_app = werkzeug.contrib.fixers.ProxyFix(app.wsgi_app)

        cls._app = app
        cls.assets = Environment(cls._app)
        cls._load_extensions()
        cls._setup_logger()
        cls._setup_db()

        cls.setup_installed_apps()
        cls._expose_models()

        try:

            # import models
            m = "%s.models" % app_directory
            werkzeug.import_string(m)
            cls._expose_models()

            # import projects views
            if not projects:
                projects = {"main": "main"}

            if project_name not in projects:
                raise ValueError("Missing project: %s" % project_name)

            _projects = projects.get(project_name)
            if isinstance(_projects, six.string_types):
                _projects = [_projects]
            for _ in _projects:
                werkzeug.import_string("%s.views.%s" % (app_directory, _))

        except ImportError as ie1:
            pass
        cls._expose_models()

        # Setup init_app
        # init_app instanciate functions that may need the flask.app object
        # Usually for flask extension to be setup
        _ = [_app(cls._app) for _app in cls._init_apps]

        # Add bundles
        cls._add_asset_bundle(cls._app.static_folder)

        # Register templates
        if cls._template_paths:
            loader = [cls._app.jinja_loader] + list(cls._template_paths)
            cls._app.jinja_loader = jinja2.ChoiceLoader(loader)

        # Static
        if cls._static_paths:
            cls.assets.load_path = [cls._app.static_folder] + list(cls._static_paths)
            [cls.assets.from_yaml(a) for a in cls._asset_bundles]

        # Register views
        for subcls in cls.__subclasses__():
            base_route = subcls.base_route
            if not base_route:
                base_route = utils.dasherize(utils.underscore(subcls.__name__))
                if subcls.__name__.lower() == "index":
                    base_route = "/"
            subcls._register(cls._app, base_route=base_route)

        return cls._app
def __call__ ( cls , flask_or_import_name , projects = None , project_name = None , app_directory = None ) : if not app_directory : app_directory = "application" if not project_name : project_name = get_app_env ( ) [ 0 ] or "main" app_env = get_env ( ) app = flask_or_import_name if isinstance ( flask_or_import_name , Flask ) else Flask ( flask_or_import_name ) app . url_map . converters [ 'regex' ] = RegexConverter app . template_folder = "%s/templates" % app_directory app . static_folder = "%s/static" % app_directory c = "%s.config.%s" % ( app_directory , app_env ) app . config . from_object ( c ) if app . config . get ( "USE_PROXY_FIX" , True ) : app . wsgi_app = werkzeug . contrib . fixers . ProxyFix ( app . wsgi_app ) cls . _app = app cls . assets = Environment ( cls . _app ) cls . _load_extensions ( ) cls . _setup_logger ( ) cls . _setup_db ( ) cls . setup_installed_apps ( ) cls . _expose_models ( ) try : m = "%s.models" % app_directory werkzeug . import_string ( m ) cls . _expose_models ( ) if not projects : projects = { "main" : "main" } if project_name not in projects : raise ValueError ( "Missing project: %s" % project_name ) _projects = projects . get ( project_name ) if isinstance ( _projects , six . string_types ) : _projects = [ _projects ] for _ in _projects : werkzeug . import_string ( "%s.views.%s" % ( app_directory , _ ) ) except ImportError as ie1 : pass cls . _expose_models ( ) _ = [ _app ( cls . _app ) for _app in cls . _init_apps ] cls . _add_asset_bundle ( cls . _app . static_folder ) if cls . _template_paths : loader = [ cls . _app . jinja_loader ] + list ( cls . _template_paths ) cls . _app . jinja_loader = jinja2 . ChoiceLoader ( loader ) if cls . _static_paths : cls . assets . load_path = [ cls . _app . static_folder ] + list ( cls . _static_paths ) [ cls . assets . from_yaml ( a ) for a in cls . _asset_bundles ] for subcls in cls . __subclasses__ ( ) : base_route = subcls . base_route if not base_route : base_route = utils . dasherize ( utils . underscore ( subcls . __name__ ) ) if subcls . __name__ . lower ( ) == "index" : base_route = "/" subcls . _register ( cls . _app , base_route = base_route ) return cls . _app
:param flask_or_import_name: Flask instance or import name -> __name__
        :param projects: dict of app and views to load. ie:
            {
                "main": [
                    "main",
                    "api"
                ]
            }
        :param project_name: name of the project. If empty, it will try to get
                             it from the app_env(). By default it is "main"
                             The app main is set as environment variable
                             ie: app=PROJECT_NAME:CONFIG -> app=main:production
        :param app_directory: the directory name relative to the current execution path
        :return: