[Zope] - How to circumvent url to object mapping ? (correction)
Jim Fulton
jim.fulton@digicool.com
Mon, 18 Jan 1999 11:15:17 -0500
Guido Sohne wrote:
>
> I want to have a URL called say,
>
> http://www.webstar.com.gh/articles/1998/01/15/Ashanti_Records_Record_Revenues
>
> which should map to a python method/object that queries an external
> database with the arguments 1998+01+15+Ashanti_Records_Record_Revenues
Do you mean 4 arguments? Or do you mean one arguments
with strings concatinated with '+'?
> Is there a way to do this *without* using Apache rewrite rules ?
Sure. The most direct way is to use the __bobo_traverse__ protocol.
If an object implements:
def __bobo_traverse__(self, REQUEST, name):
"Return an object for the given name"
....
Then this method will be called when traversing URLs.
Something like the following should work:
class Articles(...):
...
def __bobo_traverse__(self, REQUEST, name):
return ArticleFinder(name)
class ArticleFinder:
def __init__(self, name):
self._args=(name,)
def __bobo_traverse__(self, REQUEST, name):
self._args=self._args+(name,)
if len(self._args)==4:
# We have enough to find an article:
return self._getArticle()
return self
def _getArticle(self):
"""Get an article from an external database,
given self._args"""
...
Note that if you had a Z SQL Method, named 'articles'
that took arguments 'year', 'month', 'day', and
'subject', you could call it with a URL like:
http://www.webstar.com.gh/articles/year/1998/month/01/day/15/subject/Ashanti_Records_Record_Revenues
and it would extract an object from the database, assuming
that the object was uniquely identified by the arguments.
You could also add additional steps in the URL to traverse
article methods, subobject, etc.
Jim
--
Jim Fulton mailto:jim@digicool.com
Technical Director (888) 344-4332 Python Powered!
Digital Creations http://www.digicool.com http://www.python.org
Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission. Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.