混合 url 调度和遍历
我一直在开发一个使用 url 调度的应用程序。我根据这里找到的一些重要信息设置了我的根工厂: https://github.com/mmerickel/pyramid_auth_demo(感谢迈克尔!)
现在我也尝试使用pyramid_formalchemy。看来pyramid_formalchemy 使用遍历来确定授权。没关系,但我被困在一点上......
对于遍历对象需要具有位置感知能力,这意味着它们需要有一个名称和父对象。所以我有一个 User 对象。
class User(Base):
__name__ = 'user'
__parent__ = ...
我已经在 RootFactory 中定义了所需的 ACL。当 RootFactory 的构造函数被调用时,这一切都会被设置。我想将我所有类的父类设置为 RootFactory,但是创建一个 RootFactory 实例,您需要将请求传递给构造函数(特别是因为我的 RootFactory 子类 Pyramid_formalchemy.resources.Models)
但是在设置我的类时,我不这样做没有要求。
如何正确地将我的类上的 parent 设置为 RootFactory?
谢谢。
I've been working on an app that uses url dispatch. I setup my root factory based on some great info found here: https://github.com/mmerickel/pyramid_auth_demo (thanks Michael!)
Now I'm trying to use pyramid_formalchemy as well. It seems pyramid_formalchemy uses traversal for determining authorization. That's ok, but I'm stuck on one point...
For traversal objects need to be location-aware which means they need to have a name and parent. So I have a User object.
class User(Base):
__name__ = 'user'
__parent__ = ...
I've defined my desired ACLs in my RootFactory. This all gets setup when the RootFactory's constructor gets called. I'd like to set all my classes' parents to the RootFactory, but create a RootFactory instance you need to pass in a request to the constructor (particularly because my RootFactory subclasses pyramid_formalchemy.resources.Models)
But when setting up my classes I don't have a request.
How can I correctly set parent on my classes to RootFactory?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里回答了一些有关在pyramid_formalchemy中处理ACL的类似问题:
Pyramid和FormAlchemy管理员 基本上,
pyramid_formalchemy 为所有管理 URL 定义了自己的根工厂。您可以覆盖它并在那里定义一个
__acl__
(请参阅ModelsWithACL
),这可能会解决您的大多数问题。从该根开始,pyramid_formalchemy 将自动设置 __parent__ 引用。因此,如果您在对象上定义了一些特殊的__acl__
,那么将首先对其进行测试,然后ACLAuthorizationPolicy
将查看__parent__
这将是Models
或ModelsWithACL
对象。另请参阅:
http://docs.formalchemy.org/pyramid_formalchemy/#setting-permissions
I've answered some similar questions on handling ACLs within pyramid_formalchemy here:
Pyramid and FormAlchemy admin interface
Basically pyramid_formalchemy defines it's own root factory for all of the admin URLs. You can override it and define an
__acl__
there (seeModelsWithACL
) which will probably solve most of your problems. From that root, pyramid_formalchemy will automatically setup the__parent__
references. So if you define some special__acl__
on your object, that will be tested first, then theACLAuthorizationPolicy
will look at the__parent__
which would be theModels
orModelsWithACL
object.See also:
http://docs.formalchemy.org/pyramid_formalchemy/#setting-permissions