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.
183 lines
6.4 KiB
183 lines
6.4 KiB
# -*- coding: utf-8 -*-
|
|
from django.shortcuts import render_to_response
|
|
from django.views.generic import ListView, DetailView, FormView
|
|
from django.utils import translation
|
|
from django.http import HttpResponseRedirect, HttpResponse
|
|
from django.template import RequestContext
|
|
from django.core.context_processors import csrf
|
|
from django.http import Http404
|
|
from django.shortcuts import get_object_or_404
|
|
from django.utils.translation import ugettext as _
|
|
#models
|
|
from place_conference.models import PlaceConference
|
|
from country.models import Country
|
|
from city.models import City
|
|
from models import PlaceExposition
|
|
from meta.views import MetadataMixin
|
|
|
|
|
|
def catalog(request):
|
|
expo = list(PlaceExposition.objects.all())
|
|
conf = list(PlaceConference.objects.all())
|
|
places = expo+conf
|
|
|
|
args = {'objects': places}
|
|
|
|
return render_to_response('place_catalog.html', args, context_instance=RequestContext(request))
|
|
|
|
def place(request, url, photo=None):
|
|
try:
|
|
place = PlaceConference.objects.get(url=url)
|
|
except PlaceConference.DoesNotExist:
|
|
try:
|
|
place = PlaceExposition.objects.get(url=url)
|
|
except:
|
|
raise Http404
|
|
|
|
args = {'place': place}
|
|
if photo:
|
|
args['object'] = place
|
|
return render_to_response('photoreport.html', args, context_instance=RequestContext(request))
|
|
return render_to_response('place.html', args, context_instance=RequestContext(request))
|
|
|
|
from functions.custom_views import ExpoSearchView
|
|
from functions.search_forms import PlaceSearchForm
|
|
|
|
class PlaceSearchView(ExpoSearchView):
|
|
#paginate_by = 10
|
|
template_name = 'place/search.html'
|
|
search_form = PlaceSearchForm
|
|
model = PlaceExposition
|
|
|
|
class PlaceDetail(MetadataMixin, DetailView):
|
|
model = PlaceExposition
|
|
search_form = PlaceSearchForm
|
|
slug_field = 'url'
|
|
template_name = 'client/place/place_detail.html'
|
|
|
|
def get_object(self, queryset=None):
|
|
"""
|
|
Returns the object the view is displaying.
|
|
By default this requires `self.queryset` and a `pk` or `slug` argument
|
|
in the URLconf, but subclasses can override this to return any object.
|
|
"""
|
|
# Use a custom queryset if provided; this is required for subclasses
|
|
# like DateDetailView
|
|
if queryset is None:
|
|
queryset = self.get_queryset()
|
|
# Next, try looking up by primary key.
|
|
pk = self.kwargs.get(self.pk_url_kwarg, None)
|
|
slug = self.kwargs.get(self.slug_url_kwarg, None)
|
|
if pk is not None:
|
|
queryset = queryset.filter(pk=pk)
|
|
# Next, try looking up by slug.
|
|
elif slug is not None:
|
|
slug_field = self.get_slug_field()
|
|
queryset = queryset.filter(**{slug_field: slug})
|
|
# If none of those are defined, it's an error.
|
|
else:
|
|
raise AttributeError("Generic detail view %s must be called with "
|
|
"either an object pk or a slug."
|
|
% self.__class__.__name__)
|
|
try:
|
|
# Get the single item from the filtered queryset
|
|
obj = queryset.get()
|
|
except queryset.model.DoesNotExist:
|
|
try:
|
|
PlaceConference.objects.get(url=slug)
|
|
except PlaceConference.DoesNotExist:
|
|
|
|
raise Http404(_("No %(verbose_name)s found matching the query") %
|
|
{'verbose_name': queryset.model._meta.verbose_name})
|
|
return obj
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(PlaceDetail, self).get_context_data(**kwargs)
|
|
context['search_form'] = self.search_form
|
|
return context
|
|
|
|
class PlacePhoto(ListView):
|
|
template_name = 'client/place/photo.html'
|
|
obj = None
|
|
search_form = PlaceSearchForm
|
|
|
|
def get_queryset(self):
|
|
slug = self.kwargs.get('slug')
|
|
try:
|
|
place = PlaceExposition.objects.get(url=slug)
|
|
except PlaceExposition.DoesNotExist:
|
|
try:
|
|
place = PlaceConference.objects.get(url=slug)
|
|
except PlaceConference.DoesNotExist:
|
|
raise Http404(_("No %(verbose_name)s found matching the query") %
|
|
{'verbose_name': PlaceExposition._meta.verbose_name})
|
|
self.obj = place
|
|
return place.photogallery.photos.all()
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(PlacePhoto, self).get_context_data(**kwargs)
|
|
context['object'] = self.obj
|
|
context['search_form'] = self.search_form
|
|
return context
|
|
|
|
|
|
class PlaceList(MetadataMixin, ListView):
|
|
model = PlaceExposition
|
|
paginate_by = 10
|
|
template_name = 'client/place/place_list.html'
|
|
search_form = PlaceSearchForm
|
|
|
|
|
|
def get_queryset(self):
|
|
qs = super(PlaceList, self).get_queryset().order_by('-rating')
|
|
conf_qs = PlaceConference.objects.language().all()
|
|
return list(qs)+list(conf_qs)
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(PlaceList, self).get_context_data(**kwargs)
|
|
context['search_form'] = self.search_form
|
|
return context
|
|
|
|
|
|
class PlaceCatalog(MetadataMixin, ListView):
|
|
model = PlaceExposition
|
|
paginate_by = 10
|
|
template_name = 'place/catalog.html'
|
|
search_form = PlaceSearchForm
|
|
filter_object = None
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(PlaceCatalog, self).get_context_data(**kwargs)
|
|
context['search_form'] = self.search_form
|
|
context['filter_object'] = self.filter_object
|
|
|
|
context['catalog_url'] = self.catalog_url
|
|
return context
|
|
|
|
|
|
class PlaceCountryCatalog(PlaceCatalog):
|
|
catalog_url = '/places/'
|
|
|
|
def get_queryset(self):
|
|
slug = self.kwargs.get('slug')
|
|
country = get_object_or_404(Country, url=slug)
|
|
self.kwargs['country'] = country
|
|
self.filter_object = country
|
|
qs = self.model.objects.language().filter(country=country).order_by('-rating')
|
|
conf_qs = PlaceConference.objects.language().filter(country=country)
|
|
|
|
return list(qs) + list(conf_qs)
|
|
|
|
|
|
class PlaceCityCatalog(PlaceCatalog):
|
|
catalog_url = '/places/'
|
|
|
|
def get_queryset(self):
|
|
slug = self.kwargs.get('slug')
|
|
city = get_object_or_404(City, url=slug)
|
|
self.kwargs['city'] = city
|
|
self.filter_object = city
|
|
qs = self.model.objects.language().filter(city=city).order_by('-rating')
|
|
conf_qs = PlaceConference.objects.language().filter(city=city)
|
|
return list(qs) + list(conf_qs) |