Exemplo n.º 1
0
 def process_objects(self, app: FlaskUnchained,
                     blueprints: List[Blueprint]):
     for blueprint in reversed(blueprints):
         # rstrip '/' off url_prefix because views should be declaring their
         # routes beginning with '/', and if url_prefix ends with '/', routes
         # will end up looking like '/prefix//endpoint', which is no good
         url_prefix = (blueprint.url_prefix or '').rstrip('/')
         app.register_blueprint(blueprint, url_prefix=url_prefix)
Exemplo n.º 2
0
 def register_blueprint(self, app: FlaskUnchained, blueprint: Blueprint, **options):
     if app.config.get('ENABLE_URL_LANG_CODE_PREFIX'):
         url_prefix = (options.get('url_prefix', (blueprint.url_prefix or ''))
                              .rstrip('/'))
         options = dict(**options,
                        url_prefix=self.get_url_rule(url_prefix),
                        register_with_babel=False)
         app.register_blueprint(blueprint, **options)
 def run_hook(self, app: FlaskUnchained, bundles: List[Bundle]):
     for bundle_ in reversed(bundles):
         for bundle in bundle_._iter_class_hierarchy(reverse=False):
             if (bundle.template_folder or bundle._static_folders
                     or bundle._has_views()):
                 bp = BundleBlueprint(bundle)
                 for route in self.bundle.bundle_routes.get(
                         bundle.module_name, []):
                     bp.add_url_rule(route.full_rule,
                                     defaults=route.defaults,
                                     endpoint=route.endpoint,
                                     methods=route.methods,
                                     view_func=route.view_func,
                                     **route.rule_options)
                 app.register_blueprint(bp)
Exemplo n.º 4
0
    def register_routes(self, app: FlaskUnchained):
        bp = Blueprint('api-docs',
                       __name__,
                       url_prefix=app.config.API_REDOC_URL_PREFIX.rstrip('/'),
                       template_folder=os.path.join(
                           os.path.dirname(os.path.abspath(__file__)),
                           'templates'))

        # Serve json spec at `API_REDOC_URL_PREFIX/openapi.json` by default
        bp.add_url_rule(app.config.API_OPENAPI_JSON_PATH,
                        endpoint='openapi_json',
                        view_func=self._openapi_json)

        # Serve ReDoc at `API_REDOC_URL_PREFIX/` by default
        bp.add_url_rule(app.config.API_REDOC_PATH,
                        endpoint='openapi_redoc',
                        view_func=self._openapi_redoc)

        app.register_blueprint(bp, register_with_babel=False)
Exemplo n.º 5
0
    def init_app(self, app: FlaskUnchained):
        self.app = app
        self.name = app.config.ADMIN_NAME
        self.subdomain = app.config.ADMIN_SUBDOMAIN
        self._set_admin_index_view(app.config.ADMIN_INDEX_VIEW,
                                   url=app.config.ADMIN_BASE_URL)
        self.base_template = app.config.ADMIN_BASE_TEMPLATE
        self.template_mode = app.config.ADMIN_TEMPLATE_MODE

        self._init_extension()

        # Register views
        for view in self._views:
            app.register_blueprint(view.create_blueprint(self),
                                   register_with_babel=False)

        app.context_processor(
            lambda: dict(admin_base_template=self.base_template,
                         admin_view=self.index_view,
                         h=helpers,
                         get_url=url_for))
Exemplo n.º 6
0
    def register_routes(self, app: FlaskUnchained):
        redoc_url_prefix = app.config.get('API_REDOC_URL_PREFIX',
                                          '/api-docs').rstrip('/')
        template_folder = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'templates')
        bp = Blueprint('api-docs',
                       __name__,
                       url_prefix=redoc_url_prefix,
                       template_folder=template_folder)

        # Serve json spec at 'url_prefix/openapi.json' by default
        json_path = app.config.get('OPENAPI_JSON_PATH', 'openapi.json')
        bp.add_url_rule(json_path,
                        endpoint='openapi_json',
                        view_func=self._openapi_json)

        # Serve ReDoc at `url_prefix/' by default
        redoc_path = app.config.get('OPENAPI_REDOC_PATH', '/')
        bp.add_url_rule(redoc_path,
                        endpoint='openapi_redoc',
                        view_func=self._openapi_redoc)

        app.register_blueprint(bp, register_with_babel=False)