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.
 
 
 
 
 
 

238 lines
6.4 KiB

# -*- coding: utf-8 -*-
from django.views.generic import TemplateView, CreateView, ListView, UpdateView, DetailView
from django.conf import settings
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from expobanner.models import URL, BannerGroup, Banner, Paid, MainPage, Top
from expobanner.forms import UrlCreateForm, BannerCreateGroupForm, BannerCreateForm, BannerGroupUpdateForm,\
PaidCreateForm, PaidUpdateForm, TopCreateForm, BannerLinkCreateForm, MainCreateForm, MainUpdateForm, TopUpdateForm
from exposition.models import Exposition
class BannersControl(TemplateView):
template_name = 'admin/expobanner/banners_control.html'
# CREATE VIEWS
class AbstractCreate(CreateView):
template_name = 'admin/expobanner/default_form.html'
success_url = '/admin/expobanners/banners/control/'
class CreateUrl(AbstractCreate):
model = URL
form_class = UrlCreateForm
class CreateBannerGroup(AbstractCreate):
model = BannerGroup
form_class = BannerCreateGroupForm
class CreateBanner(AbstractCreate):
model = Banner
form_class = BannerCreateForm
class CreateLink(AbstractCreate):
model = Banner
form_class = BannerLinkCreateForm
# LISTS VIEWS
class AbstractList(ListView):
paginate_by = settings.ADMIN_PAGINATION
template_name = 'admin/expobanner/default_list.html'
def get_context_data(self, **kwargs):
context = super(AbstractList, self).get_context_data(**kwargs)
context['verbose'] = self.verbose
return context
class UrlList(AbstractList):
model = URL
verbose = u'Список урлов'
class BannerGroupList(AbstractList):
model = BannerGroup
verbose = u'Список груп'
class BannerList(AbstractList):
model = Banner
verbose = u'Список банеров'
template_name = 'admin/expobanner/banner_list.html'
def get_queryset(self):
qs = super(BannerList, self).get_queryset()
qs = qs.filter(group__isnull=False)
return qs
class LinkList(AbstractList):
model = Banner
verbose = u'Список ссылок'
template_name = 'admin/expobanner/link_list.html'
def get_queryset(self):
qs = super(LinkList, self).get_queryset()
qs = qs.filter(link=True)
return qs
# UPDATE VIEWS
class AbstractUpdate(UpdateView):
template_name = 'admin/expobanner/default_form.html'
success_url = '/admin/expobanners/banners/control/'
class UrlUpdate(AbstractUpdate):
model = URL
form_class = UrlCreateForm
class BannerGroupUpdate(AbstractUpdate):
model = BannerGroup
form_class = BannerGroupUpdateForm
class BannerUpdate(AbstractUpdate):
model = Banner
form_class = BannerCreateForm
class LinkUpdate(AbstractUpdate):
model = Banner
form_class = BannerLinkCreateForm
class BannerStat(DetailView):
model = Banner
template_name = 'admin/expobanner/banner_stat.html'
class PaidList(ListView):
model = Exposition
template_name = 'admin/expobanner/paid_list.html'
paginate_by = settings.ADMIN_PAGINATION
def get_queryset(self):
return self.model.objects.language().filter(paid_new__isnull=False)
class PaidCreate(CreateView):
form_class = PaidCreateForm
template_name = 'admin/expobanner/paid_create.html'
success_url = '/admin/expobanners/paid/list/'
class PaidUpdate(UpdateView):
model = Paid
form_class = PaidUpdateForm
template_name = 'admin/expobanner/paid_update.html'
success_url = '/admin/expobanners/paid/list/'
def get_initial(self):
"""
Returns the initial data to use for forms on this view.
"""
initial = super(PaidUpdate, self).get_initial()
obj = self.object
initial['tickets'] = obj.tickets.url
initial['participation'] = obj.participation.url
initial['official'] = obj.official.url
return initial
def get_context_data(self, **kwargs):
context = super(PaidUpdate, self).get_context_data(**kwargs)
obj = self.object
context['exposition'] = obj.get_event()
return context
def paid_turn(request, pk, status):
paid = get_object_or_404(Paid, pk=pk)
if status == 'on':
paid.public = True
else:
paid.public = False
paid.save()
return HttpResponseRedirect('/admin/expobanners/paid/list/')
class PaidStat(DetailView):
model = Paid
template_name = 'admin/expobanner/paid_stat.html'
# ----------------------------------
class MainList(ListView):
model = Exposition
template_name = 'admin/expobanner/main_list.html'
paginate_by = settings.ADMIN_PAGINATION
def get_queryset(self):
return self.model.objects.language().filter(main__isnull=False)
class MainCreate(CreateView):
form_class = MainCreateForm
template_name = 'admin/expobanner/paid_create.html'
success_url = '/admin/expobanners/main/list/'
class MainUpdate(UpdateView):
model = MainPage
form_class = MainUpdateForm
template_name = 'admin/expobanner/default_form.html'
success_url = '/admin/expobanners/main/list/'
def get_context_data(self, **kwargs):
context = super(MainUpdate, self).get_context_data(**kwargs)
obj = self.object
context['exposition'] = obj.get_event()
return context
def main_turn(request, pk, status):
main = get_object_or_404(MainPage, pk=pk)
if status == 'on':
main.public = True
else:
main.public = False
main.save()
return HttpResponseRedirect('/admin/expobanners/main/list/')
class MainStat(DetailView):
model = MainPage
template_name = 'admin/expobanner/paid_stat.html'
# ------------------------------------
class TopList(ListView):
model = Exposition
template_name = 'admin/expobanner/top_list.html'
paginate_by = settings.ADMIN_PAGINATION
def get_queryset(self):
return self.model.objects.language().filter(top__isnull=False)
class TopCreate(CreateView):
form_class = TopCreateForm
template_name = 'admin/expobanner/top_create.html'
success_url = '/admin/expobanners/top/list/'
class TopUpdate(UpdateView):
model = Top
form_class = TopUpdateForm
template_name = 'admin/expobanner/top_create.html'
success_url = '/admin/expobanners/top/list/'
def get_context_data(self, **kwargs):
context = super(TopUpdate, self).get_context_data(**kwargs)
obj = self.object
context['exposition'] = obj.get_event()
return context