gpt4 book ai didi

plone - 在 Plone 中从请求 ["PUBLISHED"中获取已发布的内容项

转载 作者:行者123 更新时间:2023-12-04 18:21:51 24 4
gpt4 key购买 nike

我尝试从事件中获取 IPubAfterTraversal Hook 中的上下文对象

@grok.subscribe(IPubAfterTraversal)
def admin_language_negotiator(event):
"""
Event handler which pokes the language after traversing and authentication is done, but before rendering.
"""
# Keep the current request language (negotiated on portal_languages)
# untouched

request = event.request

if not IAddonSpecific.providedBy(request):
# Add on is not active
return

context = request.get("PUBLISHED", None)

我想做:
   IContentish.providedBy(context) # Check if real content request or CSS/Image request

PUBLISHED 不是内容项上下文,但是:
    context
<FSPageTemplate at /Plone/en/plan/plan/document_view>

PUBLISHED 可能会或可能不会指向一个观点。从 HTTPRequest 中获取已发布的内容项对象(如果有)的最安全方法是什么?

最佳答案

plone.app.theming 是这样的:

def findContext(request):
"""Find the context from the request
"""
published = request.get('PUBLISHED', None)
context = getattr(published, '__parent__', None)
if context is None:
context = request.PARENTS[0]
return context

https://github.com/plone/plone.app.theming/blob/master/src/plone/app/theming/utils.py#L146

关于plone - 在 Plone 中从请求 ["PUBLISHED"中获取已发布的内容项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10489544/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com