Bad documentation for replace_urlpattern

Issue #1316 new
Martin Tiršel
created an issue

In satchmo_utils.urlhelper.replace_urlpattern:

{{{

!python

def replace_urlpattern(urlpatterns, replacement): """Delete the old urlpattern, and add a new one.

parameters:
    urlpatterns: list
    replacement: an `django.conf.urls.defaults.url` object.

example:

    replacement = url(r'^accounts/login/', 'my.site.login_signup', {}, name='auth_login'))
    replace_urlpattern(urlpatterns, replacement)
"""

...

}}}

This is confusing and not working example. The pattern to replace is found using name parameter in url function. '/accounts/' patterns are constructed using include and you are replacing the pattern in included patterns, so this removes '/accounts/login/' and replaces it with '/accounts/accounts/login/' what is not the thing the user is looking for.

It took me 1,5 hours until I discovered how it works, there is no note in documentation about this (frankly, the Satchmo documentation is very poor, please, than new features, try to focus on documentation). If you are trying to replace a pattern that is included (not a root pattern), your pattern must be the relative pattern, not absolute and you have to specify correct name parameter that matches the replaced name parameter in url function.

Comments (1)

  1. John-Scott Atlakson

    Here's a concrete example using ``replace_urlpatterns`` (which just iterates over a list of replacement patterns, calling ``replace_pattern`` for each) that illustrates the OP's point:

    from satchmo_store.urls import urlpatterns as satchmo_urlpatterns
    from satchmo_utils.urlhelper import replace_urlpatterns
    
    replace_urlpattern(
        satchmo_urlpatterns,
        [
            url(r'^$', 'my_custom.views.home', name='satchmo_shop_home'),
            # Who would guess that the following url regex would be exactly the same?
            url(r'^$', 'my_custom.views.checkout', name='satchmo_checkout-step1')
        ]
    )
    
  2. Log in to comment