Add support for brand stockist searches.

This commit is contained in:
2013-04-08 22:44:03 +01:00
parent 3886f3d456
commit 36d8535d9e
8 changed files with 150 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
from .stores import StoreListView, OnlineStoreListView, RetailStoreListView, StoreDetailView, StoreUpdateView, StoreCreateView
from .stores import StoreListView, OnlineStoreListView, RetailStoreListView, StoreDetailView, StoreUpdateView, StoreCreateView, StockistStoreListView
from .chains import ChainListView, ChainDetailView
from .search import DistanceSearchView
from .claims import ClaimCreateView
from .brands import BrandListView
from .misc import MapView

View File

@@ -0,0 +1,11 @@
from django.views.generic import ListView
from ..models import Brand
class BrandListView(ListView):
model = Brand
paginate_by = 10
def get_queryset(self):
qs = super(BrandListView, self).get_queryset()
return qs.exclude(stores=None).prefetch_related('stores')

View File

@@ -1,11 +1,11 @@
from django.views.generic import ListView, DetailView, UpdateView
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.http import HttpResponseRedirect, Http404
from django.contrib import messages
from django.contrib.formtools.wizard.views import SessionWizardView
from .mixins import EditorCheckMixin, HaystackSearchListMixin
from ..forms import AddressInline, StoreForm, AddressForm
from ..models import Store
from ..forms import StoreForm, AddressForm
from ..models import Store, Brand
class StoreListView(HaystackSearchListMixin, ListView):
@@ -43,6 +43,28 @@ class RetailStoreListView(StoreListView):
return qs.filter(store_type__in=[Store.STORE_TYPE_ONLINE, Store.STORE_TYPE_BOTH])
class StockistStoreListView(StoreListView):
template_name_suffix = '_stockist_list'
def dispatch(self, request, *args, **kwargs):
try:
self.brand = Brand.objects.get(name=kwargs.pop('brand', None))
except Brand.DoesNotExist:
raise Http404
return super(StockistStoreListView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
ctx = super(StockistStoreListView, self).get_context_data(**kwargs)
ctx.update({
'brand': self.brand,
})
return ctx
def get_queryset(self):
qs = super(StockistStoreListView, self).get_queryset()
return qs.filter(brands__in=[self.brand])
class StoreDetailView(EditorCheckMixin, DetailView):
model = Store