Constructing 'Friendly' URLs in products
Hi, I'm fairly new to Zope, so if it's a obvious answer don't kill me ;) I've been considering setting up a blog in Zope. I used to use Wordpress in PHP before I decided to give Zope a try, and I'm actually liking it so far. Anyway, I've looked at coreblog, but it gives URLs like /blog/12 and /blog/1234, I'm really looking for things like /blog/2004/11/04/wow-zope-is-cool, like Wordpress manages with the aid of mod_rewrite. Now, I guess I could do somthing like /blogposts?year=2004&month=11&day=04&title=wow-zope-is-cool through mod_rewrite, but I was wondering if there was a more zope-centric solution? About the best I could come up with was chaining a series of persistant classes which subclass Item.Folder (iirc that's the one), sort of like this: Blog->BlogYear(id=2004)->BlogMonth(id=11)->BlogDay(id=04)->BlogPost(id=wow-zope-is-cool), just a containment hierarchy. Is this good or bad thinking? I was also thinking of a single class that used something like __getattr__ to process a function or something, but I haven't though of how that would work. Probably like this myPosts = {'2004':{'11':{'04':{'wow-zope-is-cool':getBlogPost}}}}, but I'm not sure if that would even work. Comments? Suggestions? -- Phillip Hutchings http://www.sitharus.com/ sitharus@gmail.com / sitharus@sitharus.com
On Thu, Dec 02, 2004 at 03:52:02PM +1300, Phillip Hutchings wrote:
solution? About the best I could come up with was chaining a series of persistant classes which subclass Item.Folder (iirc that's the one), sort of like this: Blog->BlogYear(id=2004)->BlogMonth(id=11)->BlogDay(id=04)->BlogPost(id=wow-zope-is-cool), just a containment hierarchy. Is this good or bad thinking?
you could do that... although i suspect that for many of those you could get by with standard Folder.
I was also thinking of a single class that used something like __getattr__ to process a function or something, but I haven't though of how that would work. Probably like this myPosts = {'2004':{'11':{'04':{'wow-zope-is-cool':getBlogPost}}}}, but I'm not sure if that would even work.
Close. define __bobo_traverse__(REQUEST, name) instead of __getattr__. The latter is already heavily used by security and acquisition and attempting to overload it is likely to lead to pain and frustration. -- Paul Winkler http://www.slinkp.com
On Thu, 2 Dec 2004 01:49:11 -0500, Paul Winkler <pw_lists@slinkp.com> wrote:
On Thu, Dec 02, 2004 at 03:52:02PM +1300, Phillip Hutchings wrote:
solution? About the best I could come up with was chaining a series of persistant classes which subclass Item.Folder (iirc that's the one), sort of like this: Blog->BlogYear(id=2004)->BlogMonth(id=11)->BlogDay(id=04)->BlogPost(id=wow-zope-is-cool), just a containment hierarchy. Is this good or bad thinking?
you could do that... although i suspect that for many of those you could get by with standard Folder.
Duh! You have a very valid point there ;) Just create standard folders and populate that through an interface of sorts. So I guess it'd be a couple of scripts to do the posting, and the product to do the comments and things...
I was also thinking of a single class that used something like __getattr__ to process a function or something, but I haven't though of how that would work. Probably like this myPosts = {'2004':{'11':{'04':{'wow-zope-is-cool':getBlogPost}}}}, but I'm not sure if that would even work.
Close. define __bobo_traverse__(REQUEST, name) instead of __getattr__. The latter is already heavily used by security and acquisition and attempting to overload it is likely to lead to pain and frustration.
Ah, OK, I'll look at it. -- Phillip Hutchings http://www.sitharus.com/ sitharus@gmail.com / sitharus@sitharus.com
Phillip Hutchings wrote:
On Thu, 2 Dec 2004 01:49:11 -0500, Paul Winkler <pw_lists@slinkp.com> wrote:
On Thu, Dec 02, 2004 at 03:52:02PM +1300, Phillip Hutchings wrote:
I was also thinking of a single class that used something like __getattr__ to process a function or something, but I haven't though of how that would work. Probably like this myPosts = {'2004':{'11':{'04':{'wow-zope-is-cool':getBlogPost}}}}, but I'm not sure if that would even work.
Close. define __bobo_traverse__(REQUEST, name) instead of __getattr__. The latter is already heavily used by security and acquisition and attempting to overload it is likely to lead to pain and frustration.
Ah, OK, I'll look at it.
__getitem__ is actually simpler than __bobo_traverse__; I have often started with __bobo_traverse__, because I thought I needed it, and ended up rerwriting as __getitem__. Tres. -- =============================================================== Tres Seaver tseaver@zope.com Zope Corporation "Zope Dealers" http://www.zope.com
On Thu, Dec 02, 2004 at 10:38:20AM -0500, Tres Seaver wrote:
__getitem__ is actually simpler than __bobo_traverse__; I have often started with __bobo_traverse__, because I thought I needed it, and ended up rerwriting as __getitem__.
Good point, I tend to forget that too. Also as another respondent noted, you could solve the problem in a quick-and-dirty way by having the top-level traversed item be a Script that returns the Right Thing based on its traverse_subpath. -- Paul Winkler http://www.slinkp.com
Anyway, I've looked at coreblog, but it gives URLs like /blog/12 and /blog/1234, I'm really looking for things like /blog/2004/11/04/wow-zope-is-cool, like Wordpress manages with the aid of mod_rewrite.
Take a look at the PathHandler product (http://www.zope.org/Members/NIP/PathHandler): "The Path Handler product lets you handle URLs which don't correspond to objects." John
Phillip Hutchings wrote:
Hi,
I'm fairly new to Zope, so if it's a obvious answer don't kill me ;)
I've been considering setting up a blog in Zope. I used to use Wordpress in PHP before I decided to give Zope a try, and I'm actually liking it so far.
Anyway, I've looked at coreblog, but it gives URLs like /blog/12 and /blog/1234, I'm really looking for things like /blog/2004/11/04/wow-zope-is-cool, like Wordpress manages with the aid of mod_rewrite.
Now, I guess I could do somthing like /blogposts?year=2004&month=11&day=04&title=wow-zope-is-cool through mod_rewrite, but I was wondering if there was a more zope-centric solution? About the best I could come up with was chaining a series of persistant classes which subclass Item.Folder (iirc that's the one), sort of like this: Blog->BlogYear(id=2004)->BlogMonth(id=11)->BlogDay(id=04)->BlogPost(id=wow-zope-is-cool), just a containment hierarchy. Is this good or bad thinking? I was also thinking of a single class that used something like __getattr__ to process a function or something, but I haven't though of how that would work. Probably like this myPosts = {'2004':{'11':{'04':{'wow-zope-is-cool':getBlogPost}}}}, but I'm not sure if that would even work.
Comments? Suggestions?
Hm. If your url structure is always blog / year / month / day / name you could make 'blog' a method that parses the 'traverse_subpath' and returns the corresponding object. 'traverse_supbpath' is a sequence in the REQUEST object that contains the parts of the url after the methods name. e.g. ['2004','dec','02','hello'] HTH. Tonico
Hi, Am Donnerstag, den 02.12.2004, 15:52 +1300 schrieb Phillip Hutchings:
Hi,
I'm fairly new to Zope, so if it's a obvious answer don't kill me ;)
I've been considering setting up a blog in Zope. I used to use Wordpress in PHP before I decided to give Zope a try, and I'm actually liking it so far.
Anyway, I've looked at coreblog, but it gives URLs like /blog/12 and /blog/1234, I'm really looking for things like /blog/2004/11/04/wow-zope-is-cool, like Wordpress manages with the aid of mod_rewrite.
Now, I guess I could do somthing like /blogposts?year=2004&month=11&day=04&title=wow-zope-is-cool through mod_rewrite, but I was wondering if there was a more zope-centric solution? About the best I could come up with was chaining a series of persistant classes which subclass Item.Folder (iirc that's the one), sort of like this: Blog->BlogYear(id=2004)->BlogMonth(id=11)->BlogDay(id=04)->BlogPost(id=wow-zope-is-cool), just a containment hierarchy. Is this good or bad thinking? I was also thinking of a single class that used something like __getattr__ to process a function or something, but I haven't though of how that would work. Probably like this myPosts = {'2004':{'11':{'04':{'wow-zope-is-cool':getBlogPost}}}}, but I'm not sure if that would even work.
The most easy way to do what you want is probably store your blog entries somehow (for example in a btree2 folder - a 3rd party product to improve handling of hundreds of thousands and more objects) And use ZCatalog to index them based on some properties. make "blog" an python script object, try: return traverse_subpath (nothing more in this script) now access it via: /blog/foo/bar/wow-zope-is-cool Try some self invented URLs and see what you get. Now constructing search keys out of the URL parts should be straigt forward (if you know a little python) Hope these hints do help. Regards Tino
participants (6)
-
John Barham -
Paul Winkler -
Phillip Hutchings -
Tino Wildenhain -
Tonico Strasser -
Tres Seaver