Commits

Anonymous committed dcb703d

Rearranged URLs for Catalogues
Tidied fieldsets in Admin

  • Participants
  • Parent commits 1d24351

Comments (0)

Files changed (3)

File gnocchi/store/admin.py

 from django.contrib import admin
 from gnocchi.store import models
 
-'''
-from django.contrib.admin.filters import FieldListFilter
-from taggit.models import TaggedItem
-
-class TaggitFilter(FieldListFilter):
-    def __init__(self, field, request, params, model, model_admin, field_path):
-        super(TaggitFilter, self).__init__(
-            field, request, params, model, model_admin, field_path)
-        self.lookup_val = params.get(self.field_path)
-
-    def queryset(self, request, queryset):
-        if self.lookup_val:
-            queryset = queryset.filter(**{'%s__slug' % self.field_path: self.lookup_val})
-        return queryset
-
-    def used_params(self):
-        return [self.field_path]
-
-    def choices(self, cl):
-        yield {
-            'selected': self.lookup_val is None,
-            'query_string': cl.get_query_string({}, [self.field_path]),
-            'display': 'All',
-        }
-        for tag in TaggedItem.tags_for(cl.model):
-            yield {
-                'selected': self.lookup_val == tag.slug,
-                'query_string': cl.get_query_string({
-                    self.field_path: tag.slug,
-                }, []),
-                'display': tag.name,
-            }
-'''
-
 class ImageInline(admin.TabularInline):
     model = models.Image
     extra = 0
 
 class ProductAdmin(admin.ModelAdmin):
     list_display = ('sku', 'name', 'short_description', 'price', 'categories',)
-    #list_filter = ( ('tags', TaggitFilter), )
     inlines = [
         ImageInline,
         PriceBreakInline,
     ]
+    fieldsets = (
+        (None, {
+            'fields': (
+                ('name', 'sku',)
+                'catalogue',
+                'short_description',
+                'description',
+                ('price', 'shipping',),
+                'tags',
+            ),
+        }),
+    )
     def categories(self, obj):
         return ', '.join(obj.tags.values_list('name', flat=True))
 
-admin.site.register(models.Catalogue)
+class CatalogueAdmin(admin.ModelAdmin):
+    list_display = ('name',)
+    list_filter = ('site',)
+    prepopulated_fields = {'slug': ('name',)}
+
+admin.site.register(models.Catalogue, CatalogueAdmin)
 admin.site.register(models.Product, ProductAdmin)
 

File gnocchi/store/urls.py

 # Could import default Product model from settings, and pass to views
 
 urlpatterns = patterns('',
-    url(r'^$', ProductList.as_view()),
-    url(r'^catalogue/(?P<tags>.*)$', ProductList.as_view(), name='product-list'),
-    url(r'^product/(?P<pk>\d+)/$', ProductDetail.as_view(), name='product-detail'),
     url(r'^cart/$', CartDetail.as_view(), name='cart-detail'),
     url(r'^cart/add/$', CartAdd.as_view(), name='cart-add'),
     url(r'^cart/remove/$', CartRemove.as_view(), name='cart-del'),
+
+    url(r'^product/(?P<pk>\d+)/$', ProductDetail.as_view(), name='product-detail'),
+    url(r'^(?P<catalogue>[-\w]+/(?P<tags>.*)$', ProductList.as_view(), name='catalogue-detail'),
+
+    url(r'^$', CatalogueList.as_view()),
 )

File gnocchi/store/views.py

 import shlex
 
 __all__ = (
+    'CatalogueList',
     'ProductList', 'ProductDetail',
     'CartDetail', 'CartAdd', 'CartRemove',
 )
+
+class CatalogueList(generic.ListView):
+    model = models.Catalogue
+    context_name = 'catalogue'
+
 class ProductMixin(object):
     model = models.Product
     context_object_name = 'product'
 
     def get_queryset(self):
         qset = super(ProductList, self).get_queryset()
+        # Filter by Catalogue, if supplied
+        catalogue = self.kwargs.get('catalogue')
+        if catalogue:
+            qset = qset.filter(catalogue__slug=catalogue)
         # Filter by tags
         for tag in filter(None, self.kwargs.get('tags', '').split('/')):
             qset = qset.filter(tags__name=tag)