Looking back at my previous post it seems like I'm being aggressive or something. Sorry about that, that's 36 hours worth of sleep deprivation for you :)
OK, so I think I've roughed together an idea of how you might use URLObject in url() methods (or get_url(), or __url__(), et cetera). You can see this here [1]. I'd appreciate any comments or suggestions. One of the major advantages of URLObject is that it directly subclasses unicode, so you can use it everywhere strings are used, but it still has those handy methods and properties for manipulating/ querying the URL. -- Zack [1]: http://pastry.se/110066/ On Sep 12, 2:20 pm, Jacob Kaplan-Moss <ja...@jacobian.org> wrote: > On Sat, Sep 12, 2009 at 8:42 AM, Thomas K. Adamcik <tadam...@gmail.com> wrote: > > > In essence we could add only one new method to the API that returns a > > URL-object that provides access to the data: > > I like this idea a lot. It solves most of the problems I have with > get_absolute_url: > > * I dislike the name -- far too verbose. Why not just `obj.url()`? > * I wish there was a better mechanism for getting host-relative URLs, > schema-relative URLs, etc. The `<a href="//...">` trick is annoyingly > obscure. > * The mismatch between `...@models.permalink` and `get_absolute_url` is > very counter-intuitive. > * The fact that the returned URL is a string often means I end up > doing something like `obj.get_absolute_url().split('/')`. Objects are > better. > > > If reverse() and {% url %} methods are updated to use such an URL-object > > backwards-compatibility can probably be persevered through a proper __str__ > > method on the URL-object. > > Python's already got such an object; it's `urlparse.ParseResult` (the > object returned by `urlparse.urlparse`. We'd need a tiny subclass with > a backwards-compatible `__str__`, but that's about it. > > > I have not double checked if all the issues mentioned in > >http://code.djangoproject.com/wiki/ReplacingGetAbsoluteUrlcan be solved with > > such a scheme, but if there is interest in such a solution I'm willing to > > look > > into this and trying out the idea either as an external project or as a > > patch > > proposal. > > I'm +1 on this proposal; please ping me if you work up a patch and > I'll take a look. > > Jacob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---