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.
275 lines
7.7 KiB
275 lines
7.7 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 django.db.models import Sum
|
|
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):
|
|
qs = self.model.objects.language().filter(paid_new__isnull=False).order_by('-paid_new__public')
|
|
if self.request.GET.get('onlypublic'):
|
|
qs = qs.filter(paid_new__public=True)
|
|
return qs
|
|
|
|
|
|
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'
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(PaidStat, self).get_context_data(**kwargs)
|
|
obj = self.object
|
|
context['all'] = obj.paidstat_set.aggregate(
|
|
official=Sum('official_clicks'),
|
|
ticket=Sum('tickets_clicks'),
|
|
participation=Sum('participation_clicks'),
|
|
catalog=Sum('catalog_clicks')
|
|
)
|
|
return context
|
|
|
|
|
|
# ----------------------------------
|
|
class MainList(ListView):
|
|
model = Exposition
|
|
template_name = 'admin/expobanner/main_list.html'
|
|
paginate_by = settings.ADMIN_PAGINATION
|
|
|
|
def get_queryset(self):
|
|
qs = self.model.objects.language().filter(main__isnull=False).order_by('-main__public')
|
|
if self.request.GET.get('onlypublic'):
|
|
qs = qs.filter(main__public=True)
|
|
return qs
|
|
|
|
|
|
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/main_stat.html'
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(MainStat, self).get_context_data(**kwargs)
|
|
obj = self.object
|
|
context['stats'] = obj.link.banner_stat.all()
|
|
context['all'] = obj.link.banner_stat.aggregate(
|
|
views=Sum('view'),
|
|
clicks=Sum('click'),
|
|
unique_clicks=Sum('unique_click'),
|
|
unique_views=Sum('unique_view')
|
|
)
|
|
return context
|
|
|
|
# ------------------------------------
|
|
from datetime import date
|
|
|
|
class TopList(ListView):
|
|
model = Exposition
|
|
template_name = 'admin/expobanner/top_list.html'
|
|
paginate_by = settings.ADMIN_PAGINATION
|
|
|
|
def get_queryset(self):
|
|
qs = self.model.objects.language().filter(top__isnull=False).order_by('-top__fr')
|
|
if self.request.GET.get('onlypublic'):
|
|
qs = qs.filter(top__fr__lte=date.today(), top__to__gte=date.today())
|
|
return qs
|
|
|
|
|
|
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
|
|
|