use traversed subpath to insert REQUEST variables
Hi, you all, I have a quite large Python product which publishes (possibly multi-language) pages based on layouts which are chosen based on the user agent. Unfortunately this doesn't cache very well, and there is a lot of REQUEST fiddling during the page computation. So my idea is to put the language and layout information into the URL, e.g. www.my-site.com/en/default/home/ for the english version of the '/home' page, using the 'default' layout, and add the REQUEST variables which are set internally during traversal to the key variables used by the RAM cache manager. I reckon I need to write a __bobo_traverse__ method for my site class (in this example, rewritten to the virtual host www.my-site.com) and return the 'home' page, inserting the appropriate REQUEST variables. Is there a How-To anywhere concerning this? Thanks in advance, Tobias
Tobias Herp wrote at 2003-9-10 14:28 +0200:
... So my idea is to put the language and layout information into the URL, e.g. www.my-site.com/en/default/home/ for the english version of the '/home' page, using the 'default' layout, and add the REQUEST variables which are set internally during traversal to the key variables used by the RAM cache manager.
I reckon I need to write a __bobo_traverse__ method for my site class (in this example, rewritten to the virtual host www.my-site.com) and return the 'home' page, inserting the appropriate REQUEST variables. Is there a How-To anywhere concerning this?
You can also use a SiteAccess AccessRule for this purpose. There is a HowTo on Zope.org (a bit outdated, be careful). Dieter
Dieter Maurer schrieb:
Tobias Herp wrote at 2003-9-10 14:28 +0200:
... So my idea is to put the language and layout information into the URL, e.g. www.my-site.com/en/default/home/ for the english version of the '/home' page, using the 'default' layout, and add the REQUEST variables which are set internally during traversal to the key variables used by the RAM cache manager.
I reckon I need to write a __bobo_traverse__ method for my site class (in this example, rewritten to the virtual host www.my-site.com) and return the 'home' page, inserting the appropriate REQUEST variables. Is there a How-To anywhere concerning this?
You can also use a SiteAccess AccessRule for this purpose. There is a HowTo on Zope.org (a bit outdated, be careful).
Hi, Dieter, thanks for answering. I hoped to avoid the AccessRule thing and have a solution inside my portal product (which can contain site objects in varying level depths). A site object would easily know e.g whether or not the two following path elements are a valid language and layout. Is it more difficult or dangerous to use the __bobo_traverse__ method? Thanks, Tobias
Tobias Herp wrote:
thanks for answering. I hoped to avoid the AccessRule thing and have a solution inside my portal product (which can contain site objects in varying level depths).
In that case, have a look at how AccessRule's are implemented. Also search for my PathHandler product which might show you some other possible ways to implement... Chris
Chris Withers schrieb:
Tobias Herp wrote:
I hoped to avoid the AccessRule thing and have a solution inside my portal product (which can contain site objects in varying level depths).
In that case, have a look at how AccessRule's are implemented. Also search for my PathHandler product which might show you some other possible ways to implement...
Hi Chris, thanks, I'll do that. Tobias
Tobias Herp wrote:
thanks for answering. I hoped to avoid the AccessRule thing and have a solution inside my portal product
This is actually very easy! The BeforeTraverse machinery will call a '__before_publishing_traverse__' method defined in an object's class, even if the object has AccessRules or other contents that use this hook. Example: class MyClass: ...stuff... def __before_publishing_traverse__(self, request): # Do something with the request, such as fool with # request['TraversalRequestNameStack']. # The return value doesn't matter. Cheers, Evan @ 4-am
Evan Simpson schrieb:
def __before_publishing_traverse__(self, request): # Do something with the request, such as fool with # request['TraversalRequestNameStack']. # The return value doesn't matter.
Hi, Evan and Chris, I have a __before_publishing_traverse__ method now (which needs 'self' a second time, for whatever reason: ...(self, self2, request). I think I get along now. Thanks! Tobias
Tobias Herp wrote at 2003-9-11 11:38 +0200:
... I hoped to avoid the AccessRule thing and have a solution inside my portal product (which can contain site objects in varying level depths). A site object would easily know e.g whether or not the two following path elements are a valid language and layout.
Is it more difficult or dangerous to use the __bobo_traverse__ method?
Inside product code, "__bobo_traverse__" is (usually) easy, too. There are several differences: "__bobo_traverse__" must return an object while the basic mechanisms behind AccessRules ("__before_publishing_traverse__") can simple check things or manipulate the traversal stack and let locations to something else. "__bobo_traverse__" is used by "[un]restrictedTraverse" (and, therefore, TALES path expressions) while "__before_publishing_traverse__" is only used by ZPublisher traversal. As Evan pointed out, you do not need to use an AccessRule. You can use "__before_publishing_traverse__" in your product directly. Dieter
participants (4)
-
Chris Withers -
Dieter Maurer -
Evan Simpson -
Tobias Herp