2
發佈內容項進行的請求[「發佈」]我嘗試從事件快速在Plone
@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)
獲取上下文對象IPubAfterTraversal鉤我想要做的:
IContentish.providedBy(context) # Check if real content request or CSS/Image request
出版不是內容項上下文,但是:
context
<FSPageTemplate at /Plone/en/plan/plan/document_view>
PUBLISHED可能指向視圖,也可能不指向視圖。使用HTTPRequest獲取發佈的內容項目對象(如果有的話)的最安全方法是什麼?
作品。這裏是完整的故事:https://github.com/miohtama/silvuple/blob/master/silvuple/negotiator.py –