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.
155 lines
5.0 KiB
155 lines
5.0 KiB
# -*- coding: utf-8 -*-
|
|
import json
|
|
from itertools import chain
|
|
|
|
from django.http import HttpResponse
|
|
from django.views.generic import ListView, FormView, TemplateView
|
|
from django.shortcuts import get_object_or_404
|
|
from django.http import Http404
|
|
from django.http import HttpResponseRedirect, HttpResponse
|
|
|
|
from haystack.query import EmptySearchQuerySet
|
|
|
|
from meta.views import MetadataMixin
|
|
from accounts.models import UserLog
|
|
from exposition.models import Exposition
|
|
from conference.models import Conference
|
|
from functions.custom_views import ExpoListView
|
|
from models import Service
|
|
from order_forms import TranslationForm, CatalogForm, VisitForm, RemoteForm, ParticipationForm, TicketsForm,\
|
|
AdvertiseForm, BuildStandForm
|
|
#from functions.search_forms import CompanySearchForm
|
|
|
|
|
|
order_forms = {'translator': TranslationForm, 'catalog': CatalogForm, 'participation': ParticipationForm,
|
|
'remote': RemoteForm, 'tickets': TicketsForm, 'visit': VisitForm, 'buildstand': BuildStandForm}
|
|
|
|
meta = {
|
|
'translator': 80,
|
|
'participation': 85,
|
|
'remote': 84,
|
|
'tickets': 81,
|
|
'visit': 82
|
|
}
|
|
|
|
|
|
def get_userlog_data(request):
|
|
userlog = None
|
|
data = {}
|
|
if request.user.is_authenticated():
|
|
userlog = request.user.get_user_log()
|
|
attrs = [
|
|
'referer1', 'referer2', 'utm_source1', 'utm_medium1',
|
|
'utm_campaign1', 'utm_source2', 'utm_medium2', 'utm_campaign2',
|
|
]
|
|
search_attrs = ['search1', 'search2', 'search3',]
|
|
if userlog is not None:
|
|
for attr in chain(attrs, search_attrs):
|
|
data[attr] = getattr(userlog, attr)
|
|
else:
|
|
for attr in attrs:
|
|
data[attr] = request.session.get(attr)
|
|
for i, s in enumerate(request.session.get('search', []), start=1):
|
|
data['search' + str(i)] = s
|
|
return data
|
|
|
|
|
|
class ServiceView(MetadataMixin, FormView):
|
|
success_url = '/service/thanks/'
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
service_url = self.kwargs.get('url')
|
|
service = get_object_or_404(Service, url=service_url)
|
|
self.service = service
|
|
self.template_name = service.template
|
|
service_form = order_forms.get(service_url)
|
|
self.form_class = service_form
|
|
return super(ServiceView, self).dispatch(request, *args, **kwargs)
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
url = self.kwargs.get('url')
|
|
#service_form = order_forms.get(url)
|
|
#self.form_class = service_form
|
|
form = self.form_class(request.POST)
|
|
if form.is_valid():
|
|
return self.form_valid(form)
|
|
else:
|
|
return self.form_invalid(form)
|
|
|
|
def form_valid(self, form):
|
|
userlog = get_userlog_data(self.request)
|
|
order = form.save(commit=False, userlog=userlog)
|
|
order.save()
|
|
return HttpResponseRedirect(self.success_url)
|
|
|
|
def get_context_data(self, **kwargs):
|
|
url = self.kwargs.get('url')
|
|
meta_id = meta.get(url)
|
|
kwargs.update({'meta_id': meta_id})
|
|
return super(ServiceView, self).get_context_data(**kwargs)
|
|
|
|
|
|
def advertise(request, catalog=None, event_url=None):
|
|
if request.POST:
|
|
response = {'success': False}
|
|
form = AdvertiseForm(request.POST)
|
|
if form.is_valid():
|
|
userlog = get_userlog_data(request)
|
|
if not catalog or not event_url:
|
|
form.save(userlog=userlog)
|
|
else:
|
|
order = form.save(commit=False, userlog=userlog)
|
|
if catalog == 'expo':
|
|
try:
|
|
expo = Exposition.objects.get(url=event_url)
|
|
except Exposition.DoesNotExist:
|
|
expo = None
|
|
order.exposition = expo
|
|
elif catalog == 'conference':
|
|
try:
|
|
conf = Conference.objects.get(url=event_url)
|
|
except Conference.DoesNotExist:
|
|
conf = None
|
|
order.conference= conf
|
|
|
|
order.save()
|
|
response['success'] = True
|
|
else:
|
|
response['errors'] = form.errors
|
|
return HttpResponse(json.dumps(response), content_type='application/json')
|
|
else:
|
|
raise HttpResponse('not ajax')
|
|
|
|
|
|
from service.models import CallBack, Visit, Translation, Advertising, Participation, Remote, Tickets
|
|
|
|
class AbstractOrderListView(ListView):
|
|
template_name = 'c_admin/service/order_list.html'
|
|
paginate_by = 20
|
|
|
|
class CallBackListView(AbstractOrderListView):
|
|
model = CallBack
|
|
|
|
|
|
class VisitListView(AbstractOrderListView):
|
|
model = Visit
|
|
|
|
|
|
class TranslationListView(AbstractOrderListView):
|
|
model = Translation
|
|
|
|
class AdvertisingListView(AbstractOrderListView):
|
|
model = Advertising
|
|
|
|
class ParticipationListView(AbstractOrderListView):
|
|
model = Participation
|
|
|
|
class RemoteListView(AbstractOrderListView):
|
|
model = Remote
|
|
|
|
class TicketsListView(AbstractOrderListView):
|
|
model = Tickets
|
|
|
|
|
|
class Thanks(TemplateView):
|
|
template_name = 'client/service/thank_u_page.html'
|
|
|