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.
130 lines
4.1 KiB
130 lines
4.1 KiB
# -*- coding: utf-8 -*-
|
|
from django.http import HttpResponse
|
|
from models import Service
|
|
from functions.custom_views import ExpoListView
|
|
from django.views.generic import ListView, FormView, TemplateView
|
|
from haystack.query import EmptySearchQuerySet
|
|
from django.shortcuts import get_object_or_404
|
|
from django.http import Http404
|
|
import json
|
|
from django.http import HttpResponseRedirect, HttpResponse
|
|
from meta.views import MetadataMixin
|
|
#from functions.search_forms import CompanySearchForm
|
|
|
|
from order_forms import TranslationForm, CatalogForm, VisitForm, RemoteForm, ParticipationForm, TicketsForm,\
|
|
AdvertiseForm, BuildStandForm
|
|
|
|
|
|
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}
|
|
|
|
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):
|
|
order = form.save(commit=False)
|
|
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)
|
|
|
|
from exposition.models import Exposition
|
|
from conference.models import Conference
|
|
|
|
def advertise(request, catalog=None, event_url=None):
|
|
|
|
if request.POST:
|
|
response = {'success': False}
|
|
form = AdvertiseForm(request.POST)
|
|
if form.is_valid():
|
|
if not catalog or not event_url:
|
|
form.save()
|
|
else:
|
|
order = form.save(commit=False)
|
|
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 = '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' |