mirror of
https://github.com/nikdoof/vapemap.git
synced 2025-12-18 20:29:27 +00:00
Initial Import.
This commit is contained in:
32
app/stores/views/misc.py
Normal file
32
app/stores/views/misc.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from django.core.cache import cache
|
||||
from django.views.generic import ListView
|
||||
from ..models import Chain, Store
|
||||
|
||||
|
||||
class MapView(ListView):
|
||||
model = Store
|
||||
template_name_suffix = '_map'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super(MapView, self).get_context_data(**kwargs)
|
||||
|
||||
stores = cache.get('store_count')
|
||||
chains = cache.get('chain_count')
|
||||
|
||||
if not stores:
|
||||
stores = Store.objects.filter(active=True).count()
|
||||
cache.set('store_count', stores, 600)
|
||||
|
||||
if not chains:
|
||||
chains = Chain.objects.filter(active=True).count()
|
||||
cache.set('chain_count', chains, 600)
|
||||
|
||||
ctx.update({
|
||||
'store_count': stores,
|
||||
'chain_count': chains,
|
||||
})
|
||||
return ctx
|
||||
|
||||
def get_queryset(self):
|
||||
qs = super(MapView, self).get_queryset()
|
||||
return qs.filter(active=True).select_related('address')
|
||||
Reference in New Issue
Block a user