urlhelper.py's reverse_admin_url in satchmo-utils breaks when used in conjunction with django-localeurl

Issue #1164 open
Benoit Clennett-Sirois created an issue

urlhelper.py's reverse_admin_url in satchmo-utils breaks when used in conjunction with django-localeurl -> http://bitbucket.org/carljm/django-localeurl middleware.

Patch attached.

Can be fixed by changing

satchmo_utils/urlhelper.py function "reverse_admin_url" on line 81 as follows:

{{{
def reverse_admin_url(model, action, args=None, **kwargs):
from django.core.urlresolvers import reverse
meta = model.meta
name = 'admin:%s
%s_%s' % (meta.app_label, meta.module_name, action)
return reverse(name, args=args, kwargs=kwargs)
}}}

INSTEAD OF

{{{
def reverse_admin_url(model, action, args=None, kwargs=None):
from django.core.urlresolvers import reverse
meta = model.meta
name = 'admin:%s
%s_%s' % (meta.app_label, meta.module_name, action)
return reverse(name, args=args, kwargs=kwargs)
}}}

Comments (5)

  1. Tay Ray Chuan

    Heh, I had to read your ticket text a few times to see the change - you could have just inlined the diff.

    Please explain how this breaks your app. The non-expansion of kwargs is simply doing what django.core.urlresolvers.reverse does.

  2. Benoit Clennett-Sirois reporter

    Hi,

    It breaks my application because of the way django-localeurl returns a locale-dependant URL (http://www.example.com/LANG/path). django-localeurl prepends a two-letter string to the path, which it then uses to build urls when calling its own "reverse" function. See the code here: http://bitbucket.org/carljm/django-localeurl/src/tip/localeurl/models.py .

    If I understand correctly, by having kwargs=None, the reverse function cannot see the locale argument passed to the reverse func.

    django-localeurl is widely used to implement locale-friendly urls in Django apps. I am using it in conjunction with satchmo.

    Sorry if I am not clear enough :-)

    -- Ben

  3. Tay Ray Chuan

    From my reading of localeurl.models.reverse, it is possible to specify the locale keyword argument from satchmo_utils.urlhelper.reverse_admin_url in its existing implementation, like this:

    from satchmo_utils.urlhelper import reverse_admin_url
    reverse_admin_url(Product, 'change', args=[1], kwargs={'locale':'en-US'})
    

    The **kwargs dictionary of localeurl.models.reverse will (somewhat confusingly) contain a kwargs entry, which contains 'locale'.

    Also, shouldn't localeurl.models.reverse have a global django_reverse at the top of its definition?

  4. Log in to comment