Commits

Anonymous committed 0722b24

Remove duplicate category view and simplify URL patterns.

  • Participants
  • Parent commits 7f5456c

Comments (0)

Files changed (2)

File satchmo/shop/urls.py

 from django.conf import settings
 from satchmo.product.models import Product
 
-#The following views are custom to Satchmo
-
 urlpatterns = getattr(settings, 'SHOP_URLS', [])
 
 urlpatterns += patterns('satchmo.shop.views',
-    (r'^category/(?P<slug>[-\w]+)/$', 'category.root'),
-    (r'^category/(?P<slug_parent>[-\w]+)/(?P<slug>[-\w]+)/$', 'category.children'),
-    (r'^category/([-\w]+/)+(?P<slug_parent>[-\w]+)/(?P<slug>[-\w]+)/$', 'category.children'),
+    (r'^category/(?P<parent_slugs>[-\w]+/)*(?P<slug>[-\w]+)/$', 'category.display', {}, 'satchmo_category'),
     (r'^cart/add/$', 'cart.add', {}, 'satchmo_cart_add'),
     (r'^cart/add/ajax/$', 'cart.add_ajax', {}, 'satchmo_cart_add_ajax'),
     (r'^cart/remove/$', 'cart.remove', {}, 'satchmo_cart_remove'),
     (r'^cart/qty/ajax/$', 'cart.set_quantity_ajax', {}, 'satchmo_cart_set_qty_ajax'),
     (r'^cart/$', 'cart.display', {}, 'satchmo_cart'),
     (r'^contact/$', 'contact.form', {}, 'satchmo_contact'),
-    # override comments with our redirecting one.  OK to remove the next two URLs if you aren't using ratings
-    (r'^comments/post/$', 'comments.post_rating', { 'maxcomments' : 1 }, 'satchmo_rating_post'), 
+    (r'^checkout/', include('satchmo.payment.urls')),
+    (r'^product/', include('satchmo.product.urls')),
+
+    # Override comments with our redirecting view. You can remove the next two
+    # URLs if you aren't using ratings.
+    (r'^comments/post/$', 'comments.post_rating', {'maxcomments': 1 }, 'satchmo_rating_post'),
     (r'^comments/', include('django.contrib.comments.urls.comments')),
-    (r'^product/', include('satchmo.product.urls')),
-    # The following url is used for downloadable products
+
+    # Used to set the default language.
+    (r'^i18n/', include('django.conf.urls.i18n')),
+
+    # Used for downloadable products.
     (r'^download/process/(?P<download_key>\w+)/$', 'download.process', {}, 'satchmo_download_process'),
     (r'^download/send/(?P<download_key>\w+)/$', 'download.send_file', {}, 'satchmo_download_send'),
-    #Used to set the default language
-    (r'^i18n/', include('django.conf.urls.i18n')),
 )
-#Note with the last category url - this allows category depth to be as deep as we want but the downside
-#is that we ignore all but the child and parent category.  In practice this should be ok
 
 urlpatterns += patterns('satchmo.product.views',
     (r'^search/$', 'do_search', {}, 'satchmo_search'),
 )
 
-#Dictionaries for generic views used in Satchmo
+# Dictionaries for generic views used in Satchmo.
 
 index_dict = {
     'queryset': Product.objects.filter(active="1").filter(featured="1"),
     (r'^contact/thankyou/$','simple.direct_to_template',{'template':'thanks.html'}),
 )
 
-# add checkout urls
-urlpatterns += patterns('',
-    (r'^checkout/', include('satchmo.payment.urls')),
-)
-
-#Make sure thumbnails and images are served up properly when using the dev server
+# Make sure thumbnails and images are served up properly when using the dev server.
 if settings.LOCAL_DEV:
     urlpatterns += patterns('',
         (r'^site_media/(.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),

File satchmo/shop/views/category.py

 from satchmo.product.models import Category
 from satchmo.shop.views.utils import bad_or_missing
 
-def root(request, slug):
-    #Display the category page if we're not dealing with a child category
+def display(request, slug, parent_slugs=''):
+    # Display the category, its child categories, and its products.
     try:
         category = Category.objects.get(slug=slug)
     except Category.DoesNotExist:
     return render_to_response('base_category.html',
         {'category': category, 'child_categories': child_categories},
         RequestContext(request))
-
-def children(request, slug_parent, slug):
-    #Display the category if it is a child
-    try:
-        parent = Category.objects.get(slug=slug_parent)
-        category = parent.child.get(slug=slug)
-    except Category.DoesNotExist:
-        return bad_or_missing(request, _('The category you have requested does not exist.'))
-
-    child_categories = category.get_all_children()
-    return render_to_response('base_category.html',
-        {'category': category, 'child_categories': child_categories},
-        RequestContext(request))
-