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.
This commit is contained in:
parent
c4376c8a30
commit
a69bda06d7
3 changed files with 7 additions and 4 deletions
|
@ -312,7 +312,7 @@ class BaseView(GenericView, I18NView):
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def adapted(self):
|
def adapted(self):
|
||||||
return adapted(self.context, self.languageInfo)
|
return adapted(self.context, self.languageInfo, self.request)
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def baseObject(self):
|
def baseObject(self):
|
||||||
|
|
|
@ -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
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -43,10 +43,11 @@ from loops import util
|
||||||
|
|
||||||
# convenience functions
|
# convenience functions
|
||||||
|
|
||||||
def adapted(obj, langInfo=None):
|
def adapted(obj, langInfo=None, request=None):
|
||||||
""" Return adapter based on the object type's type interface.
|
""" Return adapter based on the object type's type interface.
|
||||||
"""
|
"""
|
||||||
if isinstance(obj, AdapterBase):
|
if isinstance(obj, AdapterBase):
|
||||||
|
obj.request = request
|
||||||
return obj
|
return obj
|
||||||
t = IType(obj, None)
|
t = IType(obj, None)
|
||||||
if t is not None:
|
if t is not None:
|
||||||
|
@ -57,6 +58,7 @@ def adapted(obj, langInfo=None):
|
||||||
if isinstance(adapted, I18NAdapterBase):
|
if isinstance(adapted, I18NAdapterBase):
|
||||||
adapted.languageInfo = langInfo
|
adapted.languageInfo = langInfo
|
||||||
if adapted is not None:
|
if adapted is not None:
|
||||||
|
adapted.request = request
|
||||||
return adapted
|
return adapted
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
@ -98,7 +100,7 @@ class AdapterBase(object):
|
||||||
|
|
||||||
adapts(IConcept)
|
adapts(IConcept)
|
||||||
|
|
||||||
_adapterAttributes = ('context', '__parent__',)
|
_adapterAttributes = ('context', '__parent__', 'request')
|
||||||
_contextAttributes = list(IConcept)
|
_contextAttributes = list(IConcept)
|
||||||
_noexportAttributes = ()
|
_noexportAttributes = ()
|
||||||
_textIndexAttributes = ()
|
_textIndexAttributes = ()
|
||||||
|
|
|
@ -200,6 +200,7 @@ class ILoopsAdapter(IConceptSchema):
|
||||||
|
|
||||||
context = Attribute('The underlying persistent object.')
|
context = Attribute('The underlying persistent object.')
|
||||||
uid = Attribute('Unique id of the context object.')
|
uid = Attribute('Unique id of the context object.')
|
||||||
|
request = Attribute('A a mapping with current settings, optional.')
|
||||||
|
|
||||||
def getChildren():
|
def getChildren():
|
||||||
""" Return a collection of child objects provided by the context
|
""" Return a collection of child objects provided by the context
|
||||||
|
|
Loading…
Add table
Reference in a new issue