On Aug 27, 2007, at 2:27 AM, Marcin Kasperski wrote:

OK, so it is a bug by design.

Take a look at the original example, and spend a minute thinking
whether the routes behaviour in this case is what would one expect.
And ... so how should be this very case solved?

It's not a bug by design, please read the docs as there's a misunderstanding about what naming your route does. If you assume the named route does something that the docs say it doesn't do, then sure, its a bug. But why would you assume (and expect) that named routes do something that none of the docs say they do?

Harnassing the fact that named routes load the defaults, and Routes will always attempt to use a route that uses all the defaults and arguments, here's how to handle the original example:

>>> from routes import *
>>> m = Mapper()
>>> m.connect('gallery_thumb', 'images/gallery/:(image_id)_: (image_size).jpg', image_size='thumbnail')
>>> m.connect('gallery', 'images/gallery/:(image_id).jpg')
>>> url_for('gallery_thumb', image_id=1)
'/images/gallery/1_thumbnail.jpg'
>>> url_for('gallery', image_id=1)
'/images/gallery/1.jpg'

Routes loads the 'image_size' argument from the named route, which the first route requires (because there is a static part, the '.jpg' at the end). This ensures that using 'gallery' will go to the second one as there is no image_size argument provided which it needs.

Cheers,
Ben

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to