Re: [Zope] How to get REST friendly urls from sql database

2007-02-27 Thread Gaute Amundsen
On Wednesday 21 February 2007 16:27, Paul Winkler wrote:
 On Wed, Feb 21, 2007 at 12:32:30PM +0100, Gaute Amundsen wrote:
  On Tuesday 20 February 2007 17:39, Paul Winkler wrote:
  snip
snip


 You could instead follow Andreas' suggestion and use a through-the-web
 Script.  It might look something like:

 article_id = traverse_subpath[-1]
 data =  context.get_the_data_somehow(article_id)
 return data

 Your URLs would then look like:

 http://example.com/folder_id/script_id/article_id

I had no idea it could be that simple.
And certainly not from Andreas riddles ;)
That will do nicely for now.

Thanks

Gaute

 --

 Paul Winkler
 http://www.slinkp.com
 ___
 Zope maillist  -  Zope@zope.org
 http://mail.zope.org/mailman/listinfo/zope
 **   No cross posts or HTML encoding!  **
 (Related lists -
  http://mail.zope.org/mailman/listinfo/zope-announce
  http://mail.zope.org/mailman/listinfo/zope-dev )
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How to get REST friendly urls from sql database

2007-02-21 Thread Gaute Amundsen
On Tuesday 20 February 2007 16:37, Andreas Jung wrote:
 --On 20. Februar 2007 16:30:43 +0100 Gaute Amundsen [EMAIL PROTECTED] wrote:
  Hi.
 
  Normally a url to an article in our CMS system would look roughly like
  this: http://www.dom.tld/aritcles/25245
 
  Where 25245 would be an object of some metatype, say 'article'.
 
  Now what if I wanted to get the data for that page from an sql server
  instead,  I would expect to end up with a url like this:
 
  http://www.dom.tld/aritcles/index_html?id=25245
 
  Now, having recently read the Roy Fielding paper, and expecting to do
  some  caching, I would much prefer to have it the first way, even when I
  have to  get the data out of a DB.
 
  Anybody have any ideas on how this might be done?

 How about Apache rewrite rules or a script called index_html that fetches
 the object by its ID? That's pretty much boring straight-forward stuff :-)

 -aj


I was certain that the index_html way required the ? preceding the 
arguments to work. Easy enoug to test. Will do.

Hm.. but rewrite rules would be better I guess.
I was actually considering that solution for something else*, just before 
posting this..  D'oh!

(* the task of having the same objects appear under different urls in 
different states )

Thanks

Gaute

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How to get REST friendly urls from sql database

2007-02-21 Thread Gaute Amundsen
On Tuesday 20 February 2007 17:39, Paul Winkler wrote:
snip
 Another option is that the object at /articles could be an instance
 of a class that looks something like:

 class MyArticleContainer():

 def __before_publishing_traverse__(self, unused, request):
 # Save the rest of the path as 'traverse_subpath'.
 request.set('traverse_subpath',
 reversed(request['TraversalRequestNameStack']))
 # Tell the publisher to stop traversing now.
 request['TraversalRequestNameStack'][:] = []

 def __call__(self, *args, **kw):
 subpath = self.REQUEST['traverse_subpath']
 data = get_data_however_you_like(subpath)
 return data


 For background, read the stuff about traversal hooks at
 http://wiki.zope.org/zope2/ZPublisher


Hm.. that looks more like what I had in mind when I posted, but allso quite a 
bit more overhead than rewriterules.
At least for me that has never written a product.

I will have to think about that one..
Would you care to elaborate a little bit on what the tradeoffs would be?

If I wanted my articles in many variants, ie. a large state space, I guess 
this way would be good?

Gaute


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How to get REST friendly urls from sql database

2007-02-21 Thread Paul Winkler
On Wed, Feb 21, 2007 at 12:32:30PM +0100, Gaute Amundsen wrote:
 On Tuesday 20 February 2007 17:39, Paul Winkler wrote:
 snip
  Another option is that the object at /articles could be an instance
  of a class that looks something like:
 
  class MyArticleContainer():
 
  def __before_publishing_traverse__(self, unused, request):
  # Save the rest of the path as 'traverse_subpath'.
  request.set('traverse_subpath',
  reversed(request['TraversalRequestNameStack']))
  # Tell the publisher to stop traversing now.
  request['TraversalRequestNameStack'][:] = []
 
  def __call__(self, *args, **kw):
  subpath = self.REQUEST['traverse_subpath']
  data = get_data_however_you_like(subpath)
  return data
 
 
  For background, read the stuff about traversal hooks at
  http://wiki.zope.org/zope2/ZPublisher
 
 
 Hm.. that looks more like what I had in mind when I posted, but allso quite a 
 bit more overhead than rewriterules.
 At least for me that has never written a product.

Well, it may feel like a lot of work to you the first time :-)

 I will have to think about that one..
 Would you care to elaborate a little bit on what the tradeoffs would be?

My approach might be good if:

- the logic for looking up articles is more complex than can be
comfortably expressed using apache rewrite rules, and/or

- the logic for looking up articles requires state that's internal to zope.


You could instead follow Andreas' suggestion and use a through-the-web
Script.  It might look something like:

article_id = traverse_subpath[-1]
data =  context.get_the_data_somehow(article_id)
return data

Your URLs would then look like:

http://example.com/folder_id/script_id/article_id

Note that naming the script index_html doesn't really help, because
http://example.com/folder_id/article_id wouldn't invoke the script.

--

Paul Winkler
http://www.slinkp.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] How to get REST friendly urls from sql database

2007-02-20 Thread Gaute Amundsen
Hi.

Normally a url to an article in our CMS system would look roughly like this:
http://www.dom.tld/aritcles/25245

Where 25245 would be an object of some metatype, say 'article'.

Now what if I wanted to get the data for that page from an sql server instead, 
I would expect to end up with a url like this:

http://www.dom.tld/aritcles/index_html?id=25245

Now, having recently read the Roy Fielding paper, and expecting to do some 
caching, I would much prefer to have it the first way, even when I have to 
get the data out of a DB.

Anybody have any ideas on how this might be done?


Regards

Gaute Amundsen
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How to get REST friendly urls from sql database

2007-02-20 Thread Andreas Jung



--On 20. Februar 2007 16:30:43 +0100 Gaute Amundsen [EMAIL PROTECTED] wrote:


Hi.

Normally a url to an article in our CMS system would look roughly like
this: http://www.dom.tld/aritcles/25245

Where 25245 would be an object of some metatype, say 'article'.

Now what if I wanted to get the data for that page from an sql server
instead,  I would expect to end up with a url like this:

http://www.dom.tld/aritcles/index_html?id=25245

Now, having recently read the Roy Fielding paper, and expecting to do
some  caching, I would much prefer to have it the first way, even when I
have to  get the data out of a DB.

Anybody have any ideas on how this might be done?


How about Apache rewrite rules or a script called index_html that fetches
the object by its ID? That's pretty much boring straight-forward stuff :-)

-aj

pgpXSYtkaHlbN.pgp
Description: PGP signature
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How to get REST friendly urls from sql database

2007-02-20 Thread Paul Winkler
On Tue, Feb 20, 2007 at 04:37:41PM +0100, Andreas Jung wrote:
 --On 20. Februar 2007 16:30:43 +0100 Gaute Amundsen [EMAIL PROTECTED] wrote:
 
 Hi.
 
 Normally a url to an article in our CMS system would look roughly like
 this: http://www.dom.tld/aritcles/25245
(snip)
 Anybody have any ideas on how this might be done?
 
 How about Apache rewrite rules or a script called index_html that fetches
 the object by its ID? That's pretty much boring straight-forward stuff :-)

Another option is that the object at /articles could be an instance
of a class that looks something like:

class MyArticleContainer():

def __before_publishing_traverse__(self, unused, request):
# Save the rest of the path as 'traverse_subpath'.
request.set('traverse_subpath',
reversed(request['TraversalRequestNameStack']))
# Tell the publisher to stop traversing now.
request['TraversalRequestNameStack'][:] = []

def __call__(self, *args, **kw):
subpath = self.REQUEST['traverse_subpath']
data = get_data_however_you_like(subpath)
return data


For background, read the stuff about traversal hooks at
http://wiki.zope.org/zope2/ZPublisher


-- 

Paul Winkler
http://www.slinkp.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )