I am writing a custom product and would like to make use of the URL string to do some cool stuff. When writing a "Python Script" there is a handy variable called traverse_subpath that contains the elements of the URL to the right of the name of the script itself. However, Zope tends to raise an exception when I attempt this technique with other types of objects, namely the objects created with my custom product code. For example: http://www.mysite.com/myPythonScript/extra/stuff works fine, and I have access to a handy list like ['extra', 'stuff'] http://www.mysite.com/myCustomObject/extra/stuff raises an error, something like: Zope has encountered a problem publishing your object. Is there a quick trick to incorporate traverse_subpath functionality into my product? Thanks!
nwingfield@che-llp.com wrote:
I am writing a custom product and would like to make use of the URL string to do some cool stuff. When writing a "Python Script" there is a handy variable called traverse_subpath that contains the elements of the URL to the right of the name of the script itself. However, Zope tends to raise an exception when I attempt this technique with other types of objects, namely the objects created with my custom product code.
For example:
http://www.mysite.com/myPythonScript/extra/stuff works fine, and I have access to a handy list like ['extra', 'stuff']
http://www.mysite.com/myCustomObject/extra/stuff raises an error, something like: Zope has encountered a problem publishing your object.
Is there a quick trick to incorporate traverse_subpath functionality into my product?
http://zope.org/Documentation/Books/ZDG/current/ObjectPublishing.stx under "traversal methods". By providing a __bobo_traverse__ you can stop traversal and provide a traversal sub-path to your object, just like Python scripts do. In fact, you can probably hunt that very code down for inspiration. Probably it goes very much like:: def __bobo_traverse__(self, request, key): if request.has_key('TraversalRequestNameStack'): self.traverse_subpath = request['TraversalRequestNameStack'] return self But keep in mind I just made that up. You'll probably have to do some work on the traversal path. I don't even recall if you get the whole thing, or only what you're involved in. Also: http://zope.org/Members/teyc/Wiki/BoboTraverse Once you do this, it would be a nice recipe on zopelabs.com. --jcc -- "Code generators follow the 80/20 rule. They solve most of the problems, but not all of the problems. There are always features and edge cases that will need hand-coding. Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design." (http://www.devx.com/java/editorial/15511)
On Thursday 22 January 2004 06:03 pm, J Cameron Cooper wrote:
nwingfield@che-llp.com wrote:
I am writing a custom product and would like to make use of the URL string to do some cool stuff. When writing a "Python Script" there is a handy variable called traverse_subpath that contains the elements of the URL to the right of the name of the script itself. However, Zope tends to raise an exception when I attempt this technique with other types of objects, namely the objects created with my custom product code.
under "traversal methods". By providing a __bobo_traverse__ you can stop traversal and provide a traversal sub-path to your object, just like Python scripts do. In fact, you can probably hunt that very code down for inspiration. Probably it goes very much like::
I use this feature in my VarImage product. You can download a copy of version 2.3.1 from http://sourceforge.net/projects/narya-project or from my own site at http://www.anansispaceworks.com/papers_html . You'll also note that I chose to use __getitem__ as well so that python code can use the mapping syntax, like http://url/to/my_varimage['tn_100.jpg'] The REFERER blocking doesn't work quite like I want it to, but the __bobo_traverse__ call shows a typical application. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com
participants (3)
-
J Cameron Cooper -
nwingfield@che-llp.com -
Terry Hancock