我想创建一个能够访问URL参数并验证某些内容的自定义谓词检查器。但是我想使用laster_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参数,并以我上面写的方式使用它。

有帮助吗?

解决方案

可能需要使用 控制器Protector

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top