2

イベントから IPubAfterTraversal フックでコンテキスト オブジェクトを取得しようとしています

@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 から取得する最も安全な方法は何ですか?

4

1 に答える 1

4

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

于 2012-05-07T21:55:12.640 に答える