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.
 
 
 
 
 
 

77 lines
2.8 KiB

import json
from article.models import Article
from django.http import HttpResponse, HttpResponseNotAllowed
from django.shortcuts import HttpResponse
from django.views.generic import FormView, TemplateView
from emencia.django.newsletter.models import Contact
from functions.cache_mixin import JitterCacheMixin
from meta.views import MetadataMixin
#from forms import CallbackForm
from service.order_forms import CallBackForm, ParticipationLandingForm
from settings.models import LandingComment, LandingParticipationComment
class AdvertisingView(MetadataMixin, TemplateView):
template_name = 'simple_pages/advertising.html'
class AdvertisingViewLanding(JitterCacheMixin, AdvertisingView):
template_name = 'simple_pages/advertising_landing.html'
def get_context_data(self, **kwargs):
context = super(AdvertisingViewLanding, self).get_context_data(**kwargs)
context['comments'] = LandingComment.objects.language().all()
return context
class ParticipationViewLanding(JitterCacheMixin, MetadataMixin, FormView):
template_name = 'simple_pages/participation_landing.html'
form_class = ParticipationLandingForm
def get_initial(self):
data = super(ParticipationViewLanding, self).get_initial()
if self.request.user.is_authenticated():
data['person'] = getattr(self.request.user, 'email')
data['person_inf'] = getattr(self.request.user, 'first_name')
return data
def make_json_response(self, data):
return HttpResponse(json.dumps(data), content_type='application/json')
def post(self, request, *args, **kwargs):
if not request.is_ajax():
return HttpResponseNotAllowed()
return super(ParticipationViewLanding, self).post(request, *args, **kwargs)
def form_valid(self, form):
form.save()
return self.make_json_response({'success': True})
def form_invalid(self, form):
data = {'success': False, 'errors': form.errors}
return self.make_json_response(data)
def get_context_data(self, **kwargs):
context = super(ParticipationViewLanding, self).get_context_data(**kwargs)
context['comments'] = LandingParticipationComment.objects.language().all()
context['articles'] = Article.objects.blogs().filter(theme__url='praktikum-eksponenta')[:4]
context['specialist_count'] = Contact.objects.all().count()
return context
class AboutView(MetadataMixin, TemplateView):
template_name = 'simple_pages/about.html'
def callback(request):
response = {'success': False}
if request.GET:
form = CallBackForm(request.GET)
if form.is_valid():
form.save()
response['success'] = True
else:
response['errors'] = form.errors
return HttpResponse(json.dumps(response), content_type='application/json')