mirror of
https://github.com/nikdoof/vapemap.git
synced 2025-12-24 07:09:26 +00:00
Add support for brand stockist searches.
This commit is contained in:
@@ -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
|
||||
|
||||
11
app/stores/views/brands.py
Normal file
11
app/stores/views/brands.py
Normal 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')
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user