0

我想创建一个能够访问 url 参数并验证某些内容的 repoze 自定义谓词检查器。但我想使用 allow_only 在控制器的所有范围内设置此权限检查器。就像是:

class MyController(BaseController):

    allow_only = All(not_anonymous(msg=l_(u'You must be logged on')),
                     my_custom_predicate(msg=l_(u'something wrong')))

    def index(self, **kw):
        return dict()

然后,my_custom_predicate 应该检查每个 MyController 方法中每个请求的 url 参数,并做任何事情。问题只是:如何允许 my_custom_predicate 检查 url 参数,以我上面写的方式使用它。

4

1 回答 1

0

可能你需要使用ControllerProtector

from repoze.what.plugins.pylonshq import ControllerProtector

allow_only = All(not_anonymous(msg=l_(u'You must be logged on')),
                     my_custom_predicate(msg=l_(u'something wrong')))

@ControllerProtector(allow_only)
class MyController(BaseController):

    def index(self, **kw):
        return dict()

请参阅http://code.gustavonarea.net/repoze.what-pylons/API.html上的文档

于 2010-06-18T06:06:48.850 回答