def init_app(settings_module='website.settings', set_backends=True, routes=True, attach_request_handlers=True): """Initializes the OSF. A sort of pseudo-app factory that allows you to bind settings, set up routing, and set storage backends, but only acts on a single app instance (rather than creating multiple instances). :param settings_module: A string, the settings module to use. :param set_backends: Whether to set the database storage backends. :param routes: Whether to set the url map. """ logger.info( 'Initializing the application from process {}, thread {}.'.format( os.getpid(), thread.get_ident())) # The settings module settings = importlib.import_module(settings_module) init_addons(settings, routes) with open( os.path.join(settings.STATIC_FOLDER, 'built', 'nodeCategories.json'), 'wb') as fp: json.dump(settings.NODE_CATEGORY_MAP, fp) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.base.settings') django.setup() app.debug = settings.DEBUG_MODE # default config for flask app, however, this does not affect setting cookie using set_cookie() app.config['SESSION_COOKIE_SECURE'] = settings.SESSION_COOKIE_SECURE app.config['SESSION_COOKIE_HTTPONLY'] = settings.SESSION_COOKIE_HTTPONLY if set_backends: do_set_backends(settings) if routes: try: make_url_map(app) except AssertionError: # Route map has already been created pass if attach_request_handlers: attach_handlers(app, settings) if app.debug: logger.info("Sentry disabled; Flask's debug mode enabled") else: sentry.init_app(app) logger.info("Sentry enabled; Flask's debug mode disabled") if set_backends: ensure_schemas() ensure_licenses() apply_middlewares(app, settings) return app
def init_app(settings_module='website.settings', set_backends=True, routes=True, attach_request_handlers=True): """Initializes the OSF. A sort of pseudo-app factory that allows you to bind settings, set up routing, and set storage backends, but only acts on a single app instance (rather than creating multiple instances). :param settings_module: A string, the settings module to use. :param set_backends: Deprecated. :param routes: Whether to set the url map. """ # Ensure app initialization only takes place once if app.config.get('IS_INITIALIZED', False) is True: return app setup_django() # The settings module settings = importlib.import_module(settings_module) init_addons(settings, routes) with open( os.path.join(settings.STATIC_FOLDER, 'built', 'nodeCategories.json'), 'w') as fp: json.dump(settings.NODE_CATEGORY_MAP, fp) app.debug = settings.DEBUG_MODE # default config for flask app, however, this does not affect setting cookie using set_cookie() app.config['SESSION_COOKIE_SECURE'] = settings.SESSION_COOKIE_SECURE app.config['SESSION_COOKIE_HTTPONLY'] = settings.SESSION_COOKIE_HTTPONLY app.config['SESSION_COOKIE_SAMESITE'] = settings.SESSION_COOKIE_SAMESITE if routes: try: from website.routes import make_url_map make_url_map(app) except AssertionError: # Route map has already been created pass if attach_request_handlers: attach_handlers(app, settings) if app.debug: logger.info("Sentry disabled; Flask's debug mode enabled") else: sentry.init_app(app) logger.info("Sentry enabled; Flask's debug mode disabled") apply_middlewares(app, settings) app.config['IS_INITIALIZED'] = True return app
def init_app(settings_module='website.settings', set_backends=True, routes=True, attach_request_handlers=True): """Initializes the OSF. A sort of pseudo-app factory that allows you to bind settings, set up routing, and set storage backends, but only acts on a single app instance (rather than creating multiple instances). :param settings_module: A string, the settings module to use. :param set_backends: Whether to set the database storage backends. :param routes: Whether to set the url map. """ logger.info('Initializing the application from process {}, thread {}.'.format( os.getpid(), thread.get_ident() )) # The settings module settings = importlib.import_module(settings_module) init_addons(settings, routes) with open(os.path.join(settings.STATIC_FOLDER, 'built', 'nodeCategories.json'), 'wb') as fp: json.dump(settings.NODE_CATEGORY_MAP, fp) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.base.settings') django.setup() app.debug = settings.DEBUG_MODE # default config for flask app, however, this does not affect setting cookie using set_cookie() app.config['SESSION_COOKIE_SECURE'] = settings.SESSION_COOKIE_SECURE app.config['SESSION_COOKIE_HTTPONLY'] = settings.SESSION_COOKIE_HTTPONLY if set_backends: do_set_backends(settings) if routes: try: make_url_map(app) except AssertionError: # Route map has already been created pass if attach_request_handlers: attach_handlers(app, settings) if app.debug: logger.info("Sentry disabled; Flask's debug mode enabled") else: sentry.init_app(app) logger.info("Sentry enabled; Flask's debug mode disabled") if set_backends: ensure_schemas() ensure_licenses() apply_middlewares(app, settings) return app
def init_app(settings_module='website.settings', set_backends=True, routes=True, mfr=False, attach_request_handlers=True): """Initializes the OSF. A sort of pseudo-app factory that allows you to bind settings, set up routing, and set storage backends, but only acts on a single app instance (rather than creating multiple instances). :param settings_module: A string, the settings module to use. :param set_backends: Whether to set the database storage backends. :param routes: Whether to set the url map. """ # The settings module settings = importlib.import_module(settings_module) build_log_templates(settings) init_addons(settings, routes) build_js_config_files(settings) app.debug = settings.DEBUG_MODE if mfr: init_mfr(app) if set_backends: logger.debug('Setting storage backends') set_up_storage( website.models.MODELS, storage.MongoStorage, addons=settings.ADDONS_AVAILABLE, ) if routes: try: make_url_map(app) except AssertionError: # Route map has already been created pass if attach_request_handlers: attach_handlers(app, settings) if app.debug: logger.info("Sentry disabled; Flask's debug mode enabled") else: sentry.init_app(app) logger.info("Sentry enabled; Flask's debug mode disabled") if set_backends: ensure_schemas() apply_middlewares(app, settings) return app
def init_app(settings_module='website.settings', set_backends=True, routes=True, attach_request_handlers=True): """Initializes the OSF. A sort of pseudo-app factory that allows you to bind settings, set up routing, and set storage backends, but only acts on a single app instance (rather than creating multiple instances). :param settings_module: A string, the settings module to use. :param set_backends: Whether to set the database storage backends. :param routes: Whether to set the url map. """ # The settings module settings = importlib.import_module(settings_module) build_log_templates(settings) init_addons(settings, routes) with open( os.path.join(settings.STATIC_FOLDER, 'built', 'nodeCategories.json'), 'wb') as fp: json.dump(settings.NODE_CATEGORY_MAP, fp) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.base.settings') django.setup() app.debug = settings.DEBUG_MODE if set_backends: do_set_backends(settings) if routes: try: make_url_map(app) except AssertionError: # Route map has already been created pass if attach_request_handlers: attach_handlers(app, settings) if app.debug: logger.info("Sentry disabled; Flask's debug mode enabled") else: sentry.init_app(app) logger.info("Sentry enabled; Flask's debug mode disabled") if set_backends: ensure_schemas() ensure_licenses() apply_middlewares(app, settings) return app
def init_app(settings_module='website.settings', set_backends=True, routes=True, attach_request_handlers=True): """Initializes the OSF. A sort of pseudo-app factory that allows you to bind settings, set up routing, and set storage backends, but only acts on a single app instance (rather than creating multiple instances). :param settings_module: A string, the settings module to use. :param set_backends: Whether to set the database storage backends. :param routes: Whether to set the url map. """ # The settings module settings = importlib.import_module(settings_module) build_log_templates(settings) init_addons(settings, routes) with open(os.path.join(settings.STATIC_FOLDER, 'built', 'nodeCategories.json'), 'wb') as fp: json.dump(settings.NODE_CATEGORY_MAP, fp) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.base.settings') django.setup() app.debug = settings.DEBUG_MODE if set_backends: do_set_backends(settings) if routes: try: make_url_map(app) except AssertionError: # Route map has already been created pass if attach_request_handlers: attach_handlers(app, settings) if app.debug: logger.info("Sentry disabled; Flask's debug mode enabled") else: sentry.init_app(app) logger.info("Sentry enabled; Flask's debug mode disabled") if set_backends: ensure_schemas() ensure_licenses() apply_middlewares(app, settings) return app