混合 url 调度和遍历

发布于 2024-12-13 08:20:01 字数 712 浏览 0 评论 0原文

我一直在开发一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦毁影碎の 2024-12-20 08:20:01

我在这里回答了一些有关在pyramid_formalchemy中处理ACL的类似问题:

Pyramid和FormAlchemy管理员 基本上,

pyramid_formalchemy 为所有管理 URL 定义了自己的根工厂。您可以覆盖它并在那里定义一个__acl__(请参阅ModelsWithACL),这可能会解决您的大多数问题。从该根开始,pyramid_formalchemy 将自动设置 __parent__ 引用。因此,如果您在对象上定义了一些特殊的 __acl__ ,那么将首先对其进行测试,然后 ACLAuthorizationPolicy 将查看 __parent__ 这将是ModelsModelsWithACL 对象。

另请参阅:

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 (see ModelsWithACL) 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 the ACLAuthorizationPolicy will look at the __parent__ which would be the Models or ModelsWithACL object.

See also:

http://docs.formalchemy.org/pyramid_formalchemy/#setting-permissions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文