You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
196 lines
6.3 KiB
196 lines
6.3 KiB
# -*- coding: utf-8 -*-
|
|
from django.shortcuts import render_to_response
|
|
from country.models import Country
|
|
from city.models import City
|
|
from place_exposition.models import PlaceExposition
|
|
from place_conference.models import PlaceConference
|
|
from django.views.generic import ListView, FormView
|
|
from functions.views_help import split_params
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
from forms import PlaceSearchForm
|
|
from functions.search_forms import EventSearchForm
|
|
from haystack.query import EmptySearchQuerySet
|
|
|
|
class EventSearchView(ListView):
|
|
paginate_by = 2
|
|
template_name = 'exposition/search.html'
|
|
search_form = EventSearchForm
|
|
|
|
|
|
def get_queryset(self):
|
|
if self.request.GET:
|
|
form = self.search_form(self.request.GET)
|
|
if form.is_valid():
|
|
return form.search()
|
|
else:
|
|
return EmptySearchQuerySet()
|
|
else:
|
|
return EmptySearchQuerySet()
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(EventSearchView, self).get_context_data(**kwargs)
|
|
context['search_form'] = EventSearchForm(self.request.GET)
|
|
queries = self.request.GET.copy()
|
|
if queries.has_key('page'):
|
|
del queries['page']
|
|
context['queries'] = queries
|
|
context['search_action'] = '/events/search/'
|
|
|
|
return context
|
|
|
|
class PlaceSearchView(ListView):
|
|
paginate_by = 2
|
|
template_name = 'place/search.html'
|
|
model = PlaceExposition
|
|
search_form = PlaceSearchForm
|
|
|
|
def get_queryset(self):
|
|
if self.request.GET:
|
|
form = self.search_form(self.request.GET)
|
|
if form.is_valid():
|
|
return form.search()
|
|
else:
|
|
return []
|
|
else:
|
|
return []
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(PlaceSearchView, self).get_context_data(**kwargs)
|
|
context['search_form'] = PlaceSearchForm(self.request.GET)
|
|
queries = self.request.GET.copy()
|
|
if queries.has_key('page'):
|
|
del queries['page']
|
|
context['queries'] = queries
|
|
context['search_action'] = '/places/search/'
|
|
|
|
return context
|
|
|
|
|
|
class PlaceListView(ListView):
|
|
paginate_by = 2
|
|
params = None
|
|
single_page = False
|
|
template_name = 'place_catalog_test.html'
|
|
model = 'places'
|
|
search_form = PlaceSearchForm
|
|
|
|
def get_params(self):
|
|
model_names = {'places': _(u'Места')}
|
|
model_alternative_name = {'places': 'place'}
|
|
params = [{'type':'model', 'url':self.model, 'name': model_names.get(self.model),
|
|
'alternative_name': model_alternative_name.get(self.model)}]
|
|
|
|
st = self.kwargs.get('params')
|
|
if st:
|
|
params = params + split_params(st)
|
|
|
|
return params
|
|
|
|
def get_queryset(self):
|
|
pl_ex = PlaceExposition.objects.all()
|
|
pl_conf = PlaceConference.objects.all()
|
|
|
|
params = self.get_params()
|
|
for param in params:
|
|
|
|
if param.get('type') == 'country':
|
|
country = Country.objects.safe_get(url=param.get('url'))
|
|
if country:
|
|
param['name'] = country.name
|
|
pl_ex = pl_ex.filter(country=country)
|
|
pl_conf = pl_conf.filter(country=country)
|
|
if param.get('type') == 'city':
|
|
city = City.objects.safe_get(url=param.get('url'))
|
|
if city:
|
|
param['name'] = city.name
|
|
pl_ex = pl_ex.filter(city=city)
|
|
pl_conf = pl_conf.filter(city=city)
|
|
|
|
if param.get('type') == 'place':
|
|
pl_ex = pl_ex.filter(url=param.get('url'))
|
|
if pl_ex:
|
|
query = pl_ex
|
|
else:
|
|
query = pl_conf.filter(url=param.get('url'))
|
|
|
|
self.single_page = True
|
|
|
|
if query:
|
|
param['name'] = query[0].name
|
|
|
|
#if self.request:
|
|
# views = query[0].views
|
|
# query.update(views=views+1)
|
|
self.params = params
|
|
return query
|
|
|
|
self.params = params
|
|
return list(pl_ex) + list(pl_conf)
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(PlaceListView, self).get_context_data(**kwargs)
|
|
context['filter'] = self.params
|
|
context['single_page'] = self.single_page
|
|
context['search_form'] = self.search_form
|
|
context['search_action'] = '/places/search/'
|
|
return context
|
|
|
|
class PlacePhotoView(PlaceListView):
|
|
paginate_by = 20
|
|
template_name = 'place/place_photo.html'
|
|
obj = None
|
|
|
|
def get_queryset(self):
|
|
pl_ex = PlaceExposition.objects.all()
|
|
pl_conf = PlaceConference.objects.all()
|
|
|
|
params = self.get_params()
|
|
for param in params:
|
|
|
|
if param.get('type') == 'country':
|
|
country = Country.objects.safe_get(url=param.get('url'))
|
|
if country:
|
|
param['name'] = country.name
|
|
pl_ex = pl_ex.filter(country=country)
|
|
pl_conf = pl_conf.filter(country=country)
|
|
if param.get('type') == 'city':
|
|
city = City.objects.safe_get(url=param.get('url'))
|
|
if city:
|
|
param['name'] = city.name
|
|
pl_ex = pl_ex.filter(city=city)
|
|
pl_conf = pl_conf.filter(city=city)
|
|
|
|
if param.get('type') == 'place':
|
|
pl_ex = pl_ex.filter(url=param.get('url'))
|
|
if pl_ex:
|
|
query = pl_ex
|
|
else:
|
|
query = pl_conf.filter(url=param.get('url'))
|
|
|
|
self.single_page = True
|
|
|
|
if query:
|
|
param['name'] = query[0].name
|
|
|
|
#if self.request:
|
|
# views = query[0].views
|
|
# query.update(views=views+1)
|
|
|
|
params.append({'type':'photo', 'name':_(u'Фото')})
|
|
self.params = params
|
|
self.obj = query[0]
|
|
|
|
return query[0].photos.all()
|
|
|
|
self.params = params
|
|
return list(pl_ex) + list(pl_conf)
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(PlacePhotoView, self).get_context_data(**kwargs)
|
|
context['object'] = self.obj
|
|
return context
|
|
|