|
|
|
|
@ -9,136 +9,6 @@ from django.core.urlresolvers import reverse_lazy |
|
|
|
|
from functions.views_help import split_params |
|
|
|
|
from django.utils.translation import ugettext as _ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PlaceListView(ListView): |
|
|
|
|
paginate_by = 10 |
|
|
|
|
params = None |
|
|
|
|
single_page = False |
|
|
|
|
template_name = 'place_catalog_test.html' |
|
|
|
|
model = 'places' |
|
|
|
|
order = 'data_begin' |
|
|
|
|
|
|
|
|
|
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/' |
|
|
|
|
context['type'] = 'places search' |
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
class PlacePhotoView(PlaceListView): |
|
|
|
|
paginate_by = 12 |
|
|
|
|
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].photogallery.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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------- Page views ------------------------ |
|
|
|
|
|
|
|
|
|
from forms import PageForm |
|
|
|
|
from models import Page |
|
|
|
|
|
|
|
|
|
|