James Bennett schrieb:
> On 4/4/06, limodou <[EMAIL PROTECTED]> wrote:
 >> [...]
> You've taken this completely out of context; as I understand it, Jacob
> and Adrian were not saying that the *entire* URL system should be
> replaced, only that the 'get_absolute_url' method for models doesn't
> feel right and they'd like to have something more elegant to take its
> place.

But isn't this connected? If you don't like ``get_absolute_url``, let's 
talk about alternatives. limodou simply did a proposal ... that's a 
valid point to discuss. And, hey, you're very restricted with relative
urls, and even these can break when you re-organize the hierarchy of 
your urls.

To carry this forward, I see things different than limodou:

* I want to do url configuration in exactly one place

* Any application's urls.py config cannot easily use url config settings
   from somewhere else, because it needs regexps.

==> The natural place for the whole url configuration, inclusive 
something like get_absolute_url() in urls.py. Not the settings.

The problem is, urls.py knows all about the prefixes where all the model 
views are linked in. It even knows how to add fields of the model into 
the url if you use %(name)s syntax.

Why not do it like this:

{{{
# within urls.py

(urlpatterns, url_dict) = generate_urlpatterns(
   ('model-name', 'regexp-prefix', view, optional_kwdict_for_view),
    ...)
}}}

generate_urlpatterns returns the a tuple (urlpatterns, url_dict)
url_dict is: { model_name : get_absolute_url_fn }
model_name is: a string, containing the name of the model
get_absolute_url is: a function fn(model_instance) --> string


including another urls.py would look like this:

{{{
(urlpatterns, url_dict) = generate_urlpatterns(
   ...,
   ('application', 'regexp-prefix', include('fitzefatze.urls')))
}}}

If you want to use this stuff somewhere in a view or model, do:

{{{
from yourapp import urls
from django.jabberwocky import get_absolute_url

# somewhere deep in the code ...
   get_absolute_url(urls, obj)
}}}


I see only one two problems in this:

* how to generate the string from the regular expression
* you tie the urls to the field names in the model


But both look feasible to me. Or are there any gotchas? I admit that I'm 
not so deep into the url configuration internals (yet).

If there's enough interest, I'm willing to produce a patch for this with 
the jabberwocky, of course. If you ain't afraid :-)


Michael



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to