Generating non-existent documents on the fly?
Is there a way to generate non-existent documents on the fly - some kind of "rewriting" the target URL? Example site structure /root (http://localhost/) /content layout_template some_txt A user queries http://localhost/content/some.html Obviously, "some.html" does not exist. This is where some mechanism (the one I am trying to find <g>) kicks in. It will analyze the query string, detect that there is "some_txt" and "layout_template". Based on that it will generate "some.html" on the fly. Any ideas? I'd rather not want to have question marks in the query; my attempts to play with standard_error_handler unfortunately did not yield anything. Thanks!
Stefan Hoffmeister wrote:
Is there a way to generate non-existent documents on the fly - some kind of "rewriting" the target URL?
If what you want really is rewriting of the request, you could use an Access Rule (from SiteAccess <plug> <plug>) to implement your rewriting logic. This isn't really "generating non-existent documents" except in the sense that all Zope dynamic content is. Evan
Stefan Hoffmeister wrote:
Is there a way to generate non-existent documents on the fly - some kind of "rewriting" the target URL?
Example site structure
/root (http://localhost/) /content layout_template some_txt
A user queries
http://localhost/content/some.html
Obviously, "some.html" does not exist. This is where some mechanism (the one I am trying to find <g>) kicks in. It will analyze the query string, detect that there is "some_txt" and "layout_template". Based on that it will generate "some.html" on the fly.
Any ideas?
The obvious answer here is to rename 'layout_template' to 'some.html'. That only gets you one dynamic page, though, and I take it from your question that if the user tries to access http://localhost/content/somethingelse.html and there is a somethingelse_txt, the template should fill that in too. If you want to write Python code, you could subclass a Folder and use the __bobo_traverse__ method to create the object to return. I've had good luck with this and fetching content (fully qualified HTML) out of a database backend. It's a little messy though. I'm not sure if you can get to the traversal code through a ZClass. I haven't played with them much yet. Doug ----------------------------------------------------------------------------- Doug Hellmann Greenberg News Networks, Inc. Software Engineer (Soon to be WebMD) dhellmann@gnncast.net http://www.medcast.com / http://www.webmd.com
On 20 Oct 1999 14:25:01 -0500, Stefan Hoffmeister wrote:
Is there a way to generate non-existent documents on the fly - some kind of "rewriting" the target URL?
Example site structure
/root (http://localhost/) /content layout_template some_txt
A user queries
http://localhost/content/some.html
Obviously, "some.html" does not exist. This is where some mechanism (the one I am trying to find <g>) kicks in. It will analyze the query string, detect that there is "some_txt" and "layout_template". Based on that it will generate "some.html" on the fly.
Any ideas?
There are several ways of going about this, depending on what you are doing. I don't know of a way to do it without using Python to wrap the object in a class which knows what to do with the rest of the URL. For example, say you are extracting a document from a SQL database but you want the client to save the data with a specific filename (stored in the database?). You can set the headers via something like: <!--#call "RESPONSE.setHeader('Content-Disposition', 'attachment; filename='+filename)"--> But 'filename' isn't standard (AFAIK) and isn't implement in all browsers. However, if you include the filename as the last component of the URL, browsers can (usually) deal with that. So what you need is some sort of __getitem__ or __bobo_traverse which knows how to deliver the correct file data given a query and the 'filename'. How you invoke the __bobo_traversee__ is the hard part. :^) If you are doing a SQL query with a SQL Method, you can use the Advanced Options to specify the Class name which will wrap the SQL method results. That class would include a __bobo_traverse__ method which takes the key (the filename part of the URL) and returns the result. Note that you might not even use the key because you might have all the info needed already. The __bobo_traverse__ method could set the mime headers, etc and ship the data out via a str() method or such. In the above example, the method preceeds the virtual part of the URL, You can reverse the order and have many, many virtual URL components preceed the method, again, using __bobo_traverse__. I do this with my tabular data mining product I am working on.
participants (4)
-
Doug Hellmann -
Evan Simpson -
kent@tiamat.goathill.org -
Stefan Hoffmeister