从 Renderer 实例访问 Plone 4 portlet 的分配上下文

发布于 2024-12-28 08:52:37 字数 546 浏览 1 评论 0原文

我想为 Plone4 制作一个上下文 portlet,然后将其添加到某些文件夹并在其各自的子文件夹中可见。然而,无论 portlet 显示在哪里,我都希望访问渲染器实例中 portlet 的分配上下文(它最初被放置的位置)。

class Assignment(base.Assignment):
    ...

class Renderer(base.Renderer):

    def base_folder(self):
         # self.context is the current context.
         # but how to access the folder, to which the portlet has been assigned?

...

在 self.manager 和 self.data 中搜索“分配”上下文,但没有找到任何合适的内容。

可能有一些解决方法:比如搜索从 self.context 到带有 portlet 的文件夹的路径,或者在创建 portlet 时将一些信息保存到分配的实例中,但我想知道是否有一些直接的方法?

I would like to make a context portlet for Plone4, which will be then added to certain folders and visible in their respective subfolders. However, no matter where the portlet is shown I would like to access portlet's assignment context (where it was put in the first place) in the Renderer's instance.

class Assignment(base.Assignment):
    ...

class Renderer(base.Renderer):

    def base_folder(self):
         # self.context is the current context.
         # but how to access the folder, to which the portlet has been assigned?

...

Searched for the "assignment" context in the self.manager and self.data, but has not found anything suitable.

There could be some workarounds: like searching the path from self.context up to the folder with portlet or saving some information into Assignment's instance upon portlet creation, but I wonder if there is some direct way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

似梦非梦 2025-01-04 08:52:37

我想出了以下内容,因为我想提供直接到 portlet 设置对话框的链接。我认为函数末尾context的值就是你想要的对象:

def settingsUrl(self):
    # this is odd... should be much more straightforward?
    # also, this is pretty slow.
    manager = self.manager
    context = self.context
    assignment = self.data

    allAss = []
    while not assignment in allAss:
        pam = getMultiAdapter((context,manager), IPortletAssignmentMapping)
        allAss = pam.values()
        if assignment in allAss:
            break

        if IAcquirer.providedBy(context):
            context=aq_parent(aq_inner(context))
        else:
            context = context.__parent__

    return '%s/++contextportlets++%s/%s' % (context.absolute_url(), 
                                            manager.__name__,
                                            assignment.__name__)

Upd。 2014:看起来人们也可以从 portlet 渲染器的 __portlet_metadata__ 属性中拼凑出这些信息,该属性具有键 key (赋值位置)、类别(例如“上下文”)、manager(例如“plone.rightcolumn”)和名称

I came up with the following because I wanted to provide a link directly to the portlet's settings dialog. I think the value of context at the end of the function is the object you want:

def settingsUrl(self):
    # this is odd... should be much more straightforward?
    # also, this is pretty slow.
    manager = self.manager
    context = self.context
    assignment = self.data

    allAss = []
    while not assignment in allAss:
        pam = getMultiAdapter((context,manager), IPortletAssignmentMapping)
        allAss = pam.values()
        if assignment in allAss:
            break

        if IAcquirer.providedBy(context):
            context=aq_parent(aq_inner(context))
        else:
            context = context.__parent__

    return '%s/++contextportlets++%s/%s' % (context.absolute_url(), 
                                            manager.__name__,
                                            assignment.__name__)

Upd. 2014: it also looks like one might be able to piece together this information from the portlet renderer's __portlet_metadata__ property, which has the keys key (location of assignment), category (e.g. 'context'), manager (e.g. 'plone.rightcolumn') and name.

寻找我们的幸福 2025-01-04 08:52:37
class Renderer(base.Renderer):

    def your_method(self):
        assignment_context_path = self.__portlet_metadata__['key']
        assignment_context = self.context.restrictedTraverse(assignment_context_path)    
class Renderer(base.Renderer):

    def your_method(self):
        assignment_context_path = self.__portlet_metadata__['key']
        assignment_context = self.context.restrictedTraverse(assignment_context_path)    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文