From a69bda06d743a6df5166e74264cbe28235db4e1c Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Thu, 28 Apr 2011 12:15:13 +0200 Subject: [PATCH] Provide 'request' attribute for adapted objects. Put the current request (if available) into concept or resource adapters in order to be able to access the session an follow the navigation history, e.g. getting the current parent object. The request is stored in the adapted object automatically when using the 'adapted' view property. --- browser/common.py | 2 +- common.py | 8 +++++--- interfaces.py | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/browser/common.py b/browser/common.py index a0c78c1..bb88283 100644 --- a/browser/common.py +++ b/browser/common.py @@ -312,7 +312,7 @@ class BaseView(GenericView, I18NView): @Lazy def adapted(self): - return adapted(self.context, self.languageInfo) + return adapted(self.context, self.languageInfo, self.request) @Lazy def baseObject(self): diff --git a/common.py b/common.py index 0857ce8..6de6fb3 100644 --- a/common.py +++ b/common.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2008 Helmut Merz helmutm@cy55.de +# Copyright (c) 2011 Helmut Merz helmutm@cy55.de # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -43,10 +43,11 @@ from loops import util # convenience functions -def adapted(obj, langInfo=None): +def adapted(obj, langInfo=None, request=None): """ Return adapter based on the object type's type interface. """ if isinstance(obj, AdapterBase): + obj.request = request return obj t = IType(obj, None) if t is not None: @@ -57,6 +58,7 @@ def adapted(obj, langInfo=None): if isinstance(adapted, I18NAdapterBase): adapted.languageInfo = langInfo if adapted is not None: + adapted.request = request return adapted return obj @@ -98,7 +100,7 @@ class AdapterBase(object): adapts(IConcept) - _adapterAttributes = ('context', '__parent__',) + _adapterAttributes = ('context', '__parent__', 'request') _contextAttributes = list(IConcept) _noexportAttributes = () _textIndexAttributes = () diff --git a/interfaces.py b/interfaces.py index 85bdefc..c9b05a4 100644 --- a/interfaces.py +++ b/interfaces.py @@ -200,6 +200,7 @@ class ILoopsAdapter(IConceptSchema): context = Attribute('The underlying persistent object.') uid = Attribute('Unique id of the context object.') + request = Attribute('A a mapping with current settings, optional.') def getChildren(): """ Return a collection of child objects provided by the context