Exemple #1
0
class IndicoFlask(PluginFlaskMixin, Flask):
    json_encoder = IndicoJSONEncoder
    request_class = IndicoRequest
    session_interface = IndicoSessionInterface()

    @property
    def session_cookie_name(self):
        name = super(IndicoFlask, self).session_cookie_name
        if not request.is_secure:
            name += '_http'
        return name

    def create_global_jinja_loader(self):
        default_loader = super(IndicoFlask, self).create_global_jinja_loader()
        cfg = Config.getInstance()
        customization_dir = cfg.getCustomizationDir()
        if not customization_dir:
            return default_loader
        return CustomizationLoader(
            default_loader, os.path.join(customization_dir, 'templates'),
            cfg.getCustomizationDebug())

    def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
        from indico.legacy.webinterface.rh.base import RHSimple
        # Endpoints from Flask-Multipass need to be wrapped in the RH
        # logic to get the autocommit logic and error handling for code
        # running inside the identity handler.
        if endpoint is not None and endpoint.startswith('_flaskmultipass'):
            view_func = RHSimple.wrap_function(view_func)
        return super(IndicoFlask, self).add_url_rule(rule,
                                                     endpoint=endpoint,
                                                     view_func=view_func,
                                                     **options)
Exemple #2
0
class IndicoFlask(PluginFlaskMixin, Flask):
    json_encoder = IndicoJSONEncoder
    request_class = IndicoRequest
    session_interface = IndicoSessionInterface()
    test_client_class = IndicoFlaskClient
    jinja_environment = IndicoEnvironment
    jinja_options = dict(Flask.jinja_options, undefined=StrictUndefined)

    @property
    def session_cookie_name(self):
        name = super().session_cookie_name
        if not request.is_secure:
            name += '_http'
        return name

    def create_global_jinja_loader(self):
        default_loader = super().create_global_jinja_loader()
        # use an empty list if there's no global customization dir so we can
        # add directories of plugins later once they are available
        customization_dir = os.path.join(
            config.CUSTOMIZATION_DIR,
            'templates') if config.CUSTOMIZATION_DIR else []
        return CustomizationLoader(default_loader, customization_dir,
                                   config.CUSTOMIZATION_DEBUG)

    def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
        from indico.web.rh import RHSimple

        # Endpoints from Flask-Multipass need to be wrapped in the RH
        # logic to get the autocommit logic and error handling for code
        # running inside the identity handler.
        if endpoint is not None and endpoint.startswith('_flaskmultipass'):
            view_func = RHSimple.wrap_function(view_func,
                                               disable_csrf_check=True)
        return super().add_url_rule(rule,
                                    endpoint=endpoint,
                                    view_func=view_func,
                                    **options)

    @property
    def has_static_folder(self):
        return False

    @property
    def manifest(self):
        if 'custom_manifests' in g:
            return g.custom_manifests[None]
        return current_webpack.manifest
Exemple #3
0
class IndicoFlask(PluginFlaskMixin, Flask):
    json_encoder = IndicoJSONEncoder
    request_class = IndicoRequest
    session_interface = IndicoSessionInterface()

    @property
    def session_cookie_name(self):
        name = super(IndicoFlask, self).session_cookie_name
        if not request.is_secure:
            name += '_http'
        return name

    def create_global_jinja_loader(self):
        default_loader = super(IndicoFlask, self).create_global_jinja_loader()
        customization_dir = config.CUSTOMIZATION_DIR
        if not customization_dir:
            return default_loader
        return CustomizationLoader(
            default_loader, os.path.join(customization_dir, 'templates'),
            config.CUSTOMIZATION_DEBUG)

    def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
        from indico.web.rh import RHSimple
        # Endpoints from Flask-Multipass need to be wrapped in the RH
        # logic to get the autocommit logic and error handling for code
        # running inside the identity handler.
        if endpoint is not None and endpoint.startswith('_flaskmultipass'):
            view_func = RHSimple.wrap_function(view_func)
        return super(IndicoFlask, self).add_url_rule(rule,
                                                     endpoint=endpoint,
                                                     view_func=view_func,
                                                     **options)

    def _find_error_handler(self, e):
        # XXX: this is a backport from flask 1.0
        # remove this method once flask 1.0 is out and we updated
        exc_class, code = self._get_exc_class_and_code(type(e))
        for name, c in ((request.blueprint, code), (None, code),
                        (request.blueprint, None), (None, None)):
            handler_map = self.error_handler_spec.setdefault(name, {}).get(c)
            if not handler_map:
                continue
            for cls in exc_class.__mro__:
                handler = handler_map.get(cls)
                if handler is not None:
                    return handler
Exemple #4
0
class IndicoFlask(PluginFlaskMixin, Flask):
    json_encoder = IndicoJSONEncoder
    request_class = IndicoRequest
    session_interface = IndicoSessionInterface()

    @property
    def session_cookie_name(self):
        name = super(IndicoFlask, self).session_cookie_name
        if not request.is_secure:
            name += '_http'
        return name

    def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
        from MaKaC.webinterface.rh.base import RHSimple
        # Endpoints from Flask-Multipass need to be wrapped in the RH
        # logic to get the autocommit logic and error handling for code
        # running inside the identity handler.
        if endpoint is not None and endpoint.startswith('_flaskmultipass'):
            view_func = RHSimple.wrap_function(view_func)
        return super(IndicoFlask, self).add_url_rule(rule,
                                                     endpoint=endpoint,
                                                     view_func=view_func,
                                                     **options)
Exemple #5
0
class IndicoFlask(PluginFlaskMixin, Flask):
    json_encoder = IndicoJSONEncoder
    request_class = IndicoRequest
    session_interface = IndicoSessionInterface()

    @property
    def session_cookie_name(self):
        name = super(IndicoFlask, self).session_cookie_name
        if not request.is_secure:
            name += '_http'
        return name

    def create_global_jinja_loader(self):
        default_loader = super(IndicoFlask, self).create_global_jinja_loader()
        # use an empty list if there's no global customization dir so we can
        # add directories of plugins later once they are available
        customization_dir = os.path.join(
            config.CUSTOMIZATION_DIR,
            'templates') if config.CUSTOMIZATION_DIR else []
        return CustomizationLoader(default_loader, customization_dir,
                                   config.CUSTOMIZATION_DEBUG)

    def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
        from indico.web.rh import RHSimple
        # Endpoints from Flask-Multipass need to be wrapped in the RH
        # logic to get the autocommit logic and error handling for code
        # running inside the identity handler.
        if endpoint is not None and endpoint.startswith('_flaskmultipass'):
            view_func = RHSimple.wrap_function(view_func)
        return super(IndicoFlask, self).add_url_rule(rule,
                                                     endpoint=endpoint,
                                                     view_func=view_func,
                                                     **options)

    def _find_error_handler(self, e):
        # XXX: this is a backport from flask 1.0
        # remove this method once flask 1.0 is out and we updated
        exc_class, code = self._get_exc_class_and_code(type(e))
        for name, c in ((request.blueprint, code), (None, code),
                        (request.blueprint, None), (None, None)):
            handler_map = self.error_handler_spec.setdefault(name, {}).get(c)
            if not handler_map:
                continue
            for cls in exc_class.__mro__:
                handler = handler_map.get(cls)
                if handler is not None:
                    return handler

    @property
    def static_folder(self):
        return os.path.join(self.root_path, 'web', 'static')

    @property
    def static_url_path(self):
        return '/'

    @property
    def manifest(self):
        if 'custom_manifests' in g:
            return g.custom_manifests[None]
        return current_webpack.manifest
Exemple #6
0
class IndicoFlask(PluginFlaskMixin, Flask):
    json_encoder = IndicoJSONEncoder
    request_class = IndicoRequest
    session_interface = IndicoSessionInterface()
Exemple #7
0
class IndicoFlask(Flask):
    request_class = IndicoRequest
    session_interface = IndicoSessionInterface()