diff --git a/expobanner/admin.py b/expobanner/admin.py
index 311c83f8..0fe5c1bc 100644
--- a/expobanner/admin.py
+++ b/expobanner/admin.py
@@ -3,6 +3,7 @@ from django.views.generic import TemplateView, CreateView, ListView, UpdateView,
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
@@ -32,6 +33,7 @@ class CreateBanner(AbstractCreate):
model = Banner
form_class = BannerCreateForm
+
class CreateLink(AbstractCreate):
model = Banner
form_class = BannerLinkCreateForm
@@ -67,6 +69,7 @@ class BannerList(AbstractList):
qs = qs.filter(group__isnull=False)
return qs
+
class LinkList(AbstractList):
model = Banner
verbose = u'Список ссылок'
@@ -114,7 +117,10 @@ class PaidList(ListView):
paginate_by = settings.ADMIN_PAGINATION
def get_queryset(self):
- return self.model.objects.language().filter(paid_new__isnull=False)
+ 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):
@@ -162,6 +168,18 @@ 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
@@ -169,7 +187,10 @@ class MainList(ListView):
paginate_by = settings.ADMIN_PAGINATION
def get_queryset(self):
- return self.model.objects.language().filter(main__isnull=False)
+ 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):
@@ -202,6 +223,7 @@ def main_turn(request, pk, status):
return HttpResponseRedirect('/admin/expobanners/main/list/')
+
class MainStat(DetailView):
model = MainPage
template_name = 'admin/expobanner/main_stat.html'
@@ -210,10 +232,16 @@ class MainStat(DetailView):
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
@@ -221,7 +249,10 @@ class TopList(ListView):
paginate_by = settings.ADMIN_PAGINATION
def get_queryset(self):
- return self.model.objects.language().filter(top__isnull=False)
+ 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):
diff --git a/expobanner/forms.py b/expobanner/forms.py
index 85f479ea..84d45965 100644
--- a/expobanner/forms.py
+++ b/expobanner/forms.py
@@ -267,4 +267,4 @@ class TopUpdateForm(forms.ModelForm):
top.save()
self.save_m2m()
- return top
+ return top
\ No newline at end of file
diff --git a/expobanner/models.py b/expobanner/models.py
index 5acbdca1..2208fc9a 100644
--- a/expobanner/models.py
+++ b/expobanner/models.py
@@ -113,7 +113,6 @@ class Banner(models.Model, StatMixin):
def get_admin_url(self):
return '/admin/expobanners/banners/banner/%d/edit/'%self.id
-
def key(slef):
if hasattr(settings, 'SECRET_KEY'):
key = str(datetime.now()) + settings.SECRET_KEY
@@ -206,6 +205,9 @@ class LogStat(models.Model):
def __unicode__(self):
return '%s - (%s)' % (self.banner, self.date)
+ class Meta:
+ ordering = ['-date']
+
# ------------------
class Paid(models.Model, StatMixin):
@@ -241,6 +243,9 @@ class PaidStat(models.Model):
participation_clicks = models.PositiveIntegerField(default=0)
official_clicks = models.PositiveIntegerField(default=0)
+ class Meta:
+ ordering = ['-date']
+
class Top(models.Model, StatMixin):
link = models.ForeignKey(Banner)
@@ -266,6 +271,7 @@ class Top(models.Model, StatMixin):
except IndexError:
return None
+
class TopStat(models.Model):
date = models.DateField()
theme = models.ForeignKey('theme.Theme', blank=True, null=True)
@@ -317,7 +323,6 @@ def generate_stat_pass(sender, **kwargs):
obj.save()
-
post_save.connect(generate_stat_pass, sender=Banner)
post_save.connect(generate_stat_pass, sender=Paid)
post_save.connect(generate_stat_pass, sender=Top)
diff --git a/exposition/models.py b/exposition/models.py
index 81474a3a..8a38e1a9 100644
--- a/exposition/models.py
+++ b/exposition/models.py
@@ -160,14 +160,12 @@ class Exposition(TranslatableModel, EventMixin, ExpoMixin):
paid_new = models.ForeignKey('expobanner.Paid', blank=True, null=True, on_delete=models.SET_NULL)
top = models.ForeignKey('expobanner.Top', blank=True, null=True, on_delete=models.SET_NULL)
+ main = models.ForeignKey('expobanner.MainPage', blank=True, null=True, on_delete=models.SET_NULL)
#set manager of this model(fisrt manager is default)
objects = ExpoManager()
enable = ClientManager()
imports = ExpoImportManager()
-
-
-
def __unicode__(self):
return self.lazy_translation_getter('name', unicode(self.pk))
@@ -308,6 +306,18 @@ class Exposition(TranslatableModel, EventMixin, ExpoMixin):
def theme_ids(self):
return [item['id'] for item in self.theme.all().values('id')]
+ def get_main_link(self):
+ if self.main:
+ return self.main.link.get_click_link()
+ else:
+ return self.get_permanent_url()
+
+ def get_top_link(self):
+ if self.top:
+ return self.top.link.get_click_link()
+ else:
+ return self.get_permanent_url()
+
class Statistic(TranslatableModel):
exposition = models.ForeignKey(Exposition, related_name='statistic')
diff --git a/templates/admin/expobanner/main_list.html b/templates/admin/expobanner/main_list.html
index 0175e392..a06a2411 100644
--- a/templates/admin/expobanner/main_list.html
+++ b/templates/admin/expobanner/main_list.html
@@ -1,4 +1,4 @@
-{% extends 'base.html' %}
+{% extends 'admin/base.html' %}
{% block body %}
@@ -8,7 +8,14 @@
{% block list_table %}
-
Добавить выставку
+
+
+
+
@@ -36,5 +43,13 @@
{# pagination #}
{% include 'admin/includes/admin_pagination.html' with page_obj=object_list %}
-
+
{% endblock %}
\ No newline at end of file
diff --git a/templates/admin/expobanner/main_stat.html b/templates/admin/expobanner/main_stat.html
index 1e1a5bb6..6c593bb7 100644
--- a/templates/admin/expobanner/main_stat.html
+++ b/templates/admin/expobanner/main_stat.html
@@ -1,4 +1,4 @@
-{% extends 'base.html' %}
+{% extends 'admin/base.html' %}
{% load static %}
{% block scripts %}
@@ -27,6 +27,14 @@
+
+ | Всего |
+ {{ all.views }} |
+ {{ all.clicks }} |
+
+ {{ all.unique_views}} |
+ {{ all.unique_clicks }} |
+
{% with stats=stats %}
{% for stat in stats %}
diff --git a/templates/admin/expobanner/paid_list.html b/templates/admin/expobanner/paid_list.html
index 81402128..f4996058 100644
--- a/templates/admin/expobanner/paid_list.html
+++ b/templates/admin/expobanner/paid_list.html
@@ -8,8 +8,13 @@
{% block list_table %}
-
Добавить выставку
-
+ Добавить выставку
+
+
+
+
| Выставка |
@@ -34,5 +39,13 @@
{# pagination #}
{% include 'admin/includes/admin_pagination.html' with page_obj=object_list %}
-
+
{% endblock %}
\ No newline at end of file
diff --git a/templates/admin/expobanner/paid_stat.html b/templates/admin/expobanner/paid_stat.html
index b47791c5..86bbc620 100644
--- a/templates/admin/expobanner/paid_stat.html
+++ b/templates/admin/expobanner/paid_stat.html
@@ -27,6 +27,13 @@
+
+ | За весь период |
+ {{ all.official }} |
+ {{ all.ticket }} |
+ {{ all.participation}} |
+ {{ all.catalog }} |
+
{% with stats=object.paidstat_set.all %}
{% for stat in stats %}
diff --git a/templates/admin/expobanner/top_list.html b/templates/admin/expobanner/top_list.html
index 78642de7..13110d32 100644
--- a/templates/admin/expobanner/top_list.html
+++ b/templates/admin/expobanner/top_list.html
@@ -9,6 +9,11 @@
{% block list_table %}
Добавить выставку
+
+
+
@@ -32,5 +37,13 @@
{# pagination #}
{% include 'admin/includes/admin_pagination.html' with page_obj=object_list %}
-
+
{% endblock %}
\ No newline at end of file