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.
198 lines
6.3 KiB
198 lines
6.3 KiB
# -*- coding: utf-8 -*-
|
|
from django.shortcuts import render_to_response
|
|
from django.http import HttpResponseRedirect, HttpResponse
|
|
from django.template import RequestContext
|
|
from django.shortcuts import get_object_or_404
|
|
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
|
|
#models
|
|
from models import Exposition
|
|
from accounts.models import User
|
|
from functions.custom_views import ExpoListView, ExpoMixin, EventDetail
|
|
from django.views.generic import ListView, DetailView
|
|
from haystack.query import EmptySearchQuerySet
|
|
from functions.search_forms import ExpositionSearchForm
|
|
#
|
|
import json
|
|
from django.utils.translation import ugettext as _
|
|
|
|
class ExpositionSearchView(ListView):
|
|
paginate_by = 2
|
|
template_name = 'exposition/search.html'
|
|
search_form = ExpositionSearchForm
|
|
model = Exposition
|
|
|
|
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(ExpositionSearchView, self).get_context_data(**kwargs)
|
|
|
|
context['search_form'] = ExpositionSearchForm(self.request.GET)
|
|
queries = self.request.GET.copy()
|
|
if queries.has_key('page'):
|
|
del queries['page']
|
|
context['queries'] = queries
|
|
context['search_action'] = '/expositions/search/'
|
|
|
|
return context
|
|
|
|
|
|
class ExpositionView(ExpoListView):
|
|
model = Exposition
|
|
template_name = 'event_catalog.html'
|
|
search_form = ExpositionSearchForm
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(ExpositionView, self).get_context_data(**kwargs)
|
|
context['search_action'] = '/expositions/search/'
|
|
return context
|
|
|
|
class ExpositionVisitors(ExpositionView):
|
|
model = Exposition
|
|
template_name = 'event_visitors.html'
|
|
|
|
def get_queryset(self):
|
|
|
|
params = self.get_params()
|
|
for param in params:
|
|
if param.get('type') == 'event':
|
|
exp = Exposition.objects.safe_get(url=param.get('url'))
|
|
#query = exp.users
|
|
param['name'] = exp.name
|
|
params.append({'type':'visitors', 'name':_(u'Посетители')})
|
|
|
|
self.params = params
|
|
return exp.users.all()
|
|
|
|
|
|
class ExpositionMembers(ExpoListView):
|
|
model = Exposition
|
|
template_name = 'event_members.html'
|
|
|
|
def get_queryset(self):
|
|
|
|
params = self.get_params()
|
|
for param in params:
|
|
if param.get('type') == 'event':
|
|
exp = Exposition.objects.safe_get(url=param.get('url'))
|
|
param['name'] = exp.name
|
|
#query = exp.users
|
|
params.append({'type':'members', 'name':_(u'Участники')})
|
|
self.params = params
|
|
return exp.company.all()
|
|
|
|
class ExpositionStatistic(ExpoListView):
|
|
model = Exposition
|
|
template_name = 'exposition_statistic.html'
|
|
def get_queryset(self):
|
|
params = self.get_params()
|
|
for param in params:
|
|
if param.get('type') == 'event':
|
|
exp = Exposition.objects.filter(url=param.get('url'))
|
|
param['name'] = exp[0].name
|
|
#query = exp.users
|
|
self.single_page = True
|
|
params.append({'type':'statistic', 'name':_(u'Статистика')})
|
|
self.params = params
|
|
return exp
|
|
|
|
class ExpositionProgramme(ExpoListView):
|
|
model = Exposition
|
|
template_name = 'exposition_programm.html'
|
|
def get_queryset(self):
|
|
params = self.get_params()
|
|
for param in params:
|
|
if param.get('type') == 'event':
|
|
exp = Exposition.objects.filter(url=param.get('url'))
|
|
param['name'] = exp[0].name
|
|
#query = exp.users
|
|
self.single_page = True
|
|
params.append({'type':'programme', 'name':_(u'Программа')})
|
|
self.params = params
|
|
return exp
|
|
|
|
class ExpositionPrice(ExpoListView):
|
|
model = Exposition
|
|
template_name = 'exposition_price.html'
|
|
def get_queryset(self):
|
|
params = self.get_params()
|
|
for param in params:
|
|
if param.get('type') == 'event':
|
|
exp = Exposition.objects.filter(url=param.get('url'))
|
|
param['name'] = exp[0].name
|
|
#query = exp.users
|
|
self.single_page = True
|
|
params.append({'type':'price', 'name':_(u'Стоимость посещения и участия')})
|
|
self.params = params
|
|
return exp
|
|
|
|
|
|
|
|
|
|
def exposition_add_calendar(request, id):
|
|
args = {'success': False}
|
|
user = request.user
|
|
|
|
if user.is_authenticated():
|
|
exp = Exposition.objects.safe_get(id=id)
|
|
if exp:
|
|
user.calendar.expositions.add(exp)
|
|
args['success'] = True
|
|
else:
|
|
args['not_authorized'] = True
|
|
args['success'] = True
|
|
|
|
return HttpResponse(json.dumps(args), content_type='application/json')
|
|
|
|
def exposition_remove_calendar(request, id):
|
|
args = {'success': False}
|
|
user = request.user
|
|
|
|
if user.is_authenticated():
|
|
exp = Exposition.objects.safe_get(id=id)
|
|
if exp:
|
|
user.calendar.expositions.remove(exp)
|
|
args['success'] = True
|
|
else:
|
|
args['not_authorized'] = True
|
|
args['success'] = True
|
|
|
|
|
|
return HttpResponse(json.dumps(args), content_type='application/json')
|
|
|
|
def exposition_visit(request, id):
|
|
args = {'success': False}
|
|
user = request.user
|
|
if user.is_authenticated():
|
|
exp = Exposition.objects.safe_get(id=id)
|
|
if exp:
|
|
exp.users.add(user)
|
|
args['success'] = True
|
|
|
|
else:
|
|
args['not_authorized'] = True
|
|
args['success'] = True
|
|
|
|
return HttpResponse(json.dumps(args), content_type='application/json')
|
|
|
|
def exposition_unvisit(request, id):
|
|
args = {'success': False}
|
|
user = request.user
|
|
if user.is_authenticated():
|
|
exp = Exposition.objects.safe_get(id=id)
|
|
if exp:
|
|
exp.users.remove(user)
|
|
else:
|
|
args['not_authorized'] = True
|
|
args['success'] = True
|
|
|
|
return HttpResponse(json.dumps(args), content_type='application/json') |