armstrong/armstrong — Issue #28: Proposal for get_absolute_url/default urls
Author: dmclain
Created: 2011-10-24 20:44:19+00:00
State: open
Labels: feature, wishlist

One of the issues we kicked down the road for our 11.09 release was shipping default urls on a per app basis. Since we make no assumptions about implementors' url schemes, we have a less than great implementation for get_absolute_url in armstrong.core.arm_content that calls out to a function in the user's ROOT_URLCONF called get_url_for_model. That function will end up being a giant switch statement for any large site.

We've always wanted to move to a backend based model that allows implementors to choose from different url patterns (eg '/2011/3/2/article_slug' vs. '/primary_section/child_section/article_id' or whatever).

A backend would be a module that defines the following:

* url_patterns - A standard url patterns that can be included
* get_url_for_model - takes in an object and returns the result of a reverse call
* models - a tuple of tuples, each tuple is ('app', 'model') that defines what models the get_url_for_model function knows how to handle

In the site's settings would be a setting like::

ARMSTRONG_URL_BACKENDS = [
"armstrong.core.arm_sections.urls.slug_based",
"armstrong.apps.articles.urls.date_based",
]

And in the urls::

url(r'^sections/', include(armstrong.core.arm_sections.urls)),

Inside the urlconf for an armstrong app would be roughly the following::

from armstrong.conf.urls import configurable_urls
urlpatterns = configurable_urls(__name__)

The configurable_urls function would iterate through the ARMSTRONG_URLS_BACKENDS, looking for one that is defined for the app that matches `__name__` and would then return the urlpatterns for that module

All armstrong models will similarly delegate their get_absolute_url function to get_url_for_model from the new armstrong.conf.urls module. That function will iterate through the ARMSTRONG_URLS_BACKENDS looking for one that supports the model that is being reversed and then call it.