1. Brad Pitcher
  2. satchmo-imagekit

Commits

Tay Ray Chuan  committed 96494e9 Merge

Merge in fix for admin urls

References #1137.

* commit 'c01d8c7':
satchmo_product_admin: use reverse_admin_url()
satchmo_utils.urlhelper: add reverse_admin_url()
satchmo_utils.urlhelper: strip trailing whitespace
satchmo_product_admin: don't wrap in ()
satchmo_product_admin: directly import reverse()

  • Participants
  • Parent commits 4872280, 2f66d51
  • Branches default

Comments (0)

Files changed (2)

File satchmo/apps/product/templatetags/satchmo_product_admin.py

View file
  • Ignore whitespace
 from django import template
-from django.core import urlresolvers
+from django.core.urlresolvers import reverse
 from django.template import Context, Template
 from django.utils.translation import ugettext_lazy as _
 from product import active_product_types
+from product.models import Product
+from satchmo_utils.urlhelper import reverse_admin_url
 
 register = template.Library()
 
         is_config = "ConfigurableProduct" in subtypes
         app_label = app.split(".")[-1]
         if subtype in subtypes:
-            edit_url = urlresolvers.reverse('admin:%s_%s_change' %
-                                            (app_label, subtype.lower()),
-                                            args=(product.pk,))
+            edit_url = reverse('admin:%s_%s_change' %
+                               (app_label, subtype.lower()),
+                                args=(product.pk,))
             output += ('<li><a href="%s">' % edit_url +
                        _('Edit %(subtype)s') % {'subtype': subtype} +
                        '</a></li>')
             if is_config or subtype=="ProductVariation":
-                 output += '<li><a href="%s">Variation Manager</a></li>' % (urlresolvers.reverse("satchmo_admin_variation_manager", args = [product.id]))
+                 output += '<li><a href="%s">Variation Manager</a></li>' % (reverse("satchmo_admin_variation_manager", args = [product.id]))
         else:
             if not(is_config and subtype=="ProductVariation"):
-                add_url = urlresolvers.reverse('admin:%s_%s_add' %
-                                               (app_label, subtype.lower()))
+                add_url = reverse('admin:%s_%s_add' %
+                                  (app_label, subtype.lower()))
                 output += ('<li><a href="%s?product=%s">' % (add_url, product.id) +
                            _('Add %(subtype)s') % {'subtype': subtype} +
                            '</a></li>')
 register.simple_tag(edit_subtypes)
 
 def list_variations(configurableproduct):
+    from product.modules.configurable.models import ProductVariation
+
     opts = configurableproduct.get_all_options()
     output = "{% load admin_modify adminmedia %}"
     output += "<table>"
 
         product = configurableproduct.get_product_from_options(p_opt)
         if product:
-            p_url = '/admin/product/product/%s/' % product.pk
-            pv_url = '/admin/product/productvariation/%s/delete/' % product.pk
+            p_url = reverse_admin_url(Product, 'change', args=(product.pk,))
+            pv_url = reverse_admin_url(ProductVariation, 'delete', args=(product.pk,))
             output += """
             <tr>
             <td>%s</td>
             #opt_pks = ','.join(opt_pks)
             # TODO [NFA]: Blocked by Django ticket #7738.
             opt_pks = ''
-            add_url = ('/admin/product/productvariation/add/' +
+            add_url = reverse_admin_url(ProductVariation, 'add') + \
                 "?product=%s&parent=%s&options=%s" % (
                 configurableproduct.product.pk, configurableproduct.product.pk,
-                opt_pks))
+                opt_pks)
             output += """
             <tr>
             <td>%s</td>

File satchmo/apps/satchmo_utils/urlhelper.py

View file
  • Ignore whitespace
 
 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)
     """
     else:
         name = None
         regex = replacement.regex.pattern
-    
+
     while not found and ix < len(urlpatterns):
         pattern = urlpatterns[ix]
         if hasattr(pattern, 'url_patterns'):
                 del urlpatterns[ix]
                 urlpatterns.append(replacement)
                 found = True
-                    
+
         if not found:
             ix += 1
-            
+
     return found
-    
+
 def replace_urlpatterns(urlpatterns, replacelist):
     for replace in replacelist:
         replace_urlpattern(urlpatterns, replace)
+
+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)