GET TOPS. Fix views counting

remotes/origin/1203
Kotiuk Nazarii 11 years ago
parent 2bb8d750c4
commit 3450aa0968
  1. 86
      expobanner/admin.py
  2. 12
      expobanner/admin_urls.py
  3. 105
      expobanner/forms.py
  4. 2
      expobanner/management/commands/banner_log_update.py
  5. 6
      expobanner/managers.py
  6. 25
      expobanner/models.py
  7. 5
      expobanner/views.py
  8. 1
      exposition/manager.py
  9. 7
      exposition/models.py
  10. 11
      functions/models_methods.py
  11. 7
      proj/views.py
  12. 6
      templates/admin/expobanner/banners_control.html
  13. 38
      templates/admin/expobanner/link_list.html
  14. 38
      templates/admin/expobanner/main_list.html
  15. 2
      templates/admin/expobanner/top_create.html
  16. 26
      templates/client/blank.html
  17. 4
      templates/client/includes/index/main_events.html

@ -3,9 +3,9 @@ from django.views.generic import TemplateView, CreateView, ListView, UpdateView,
from django.conf import settings from django.conf import settings
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from expobanner.models import URL, BannerGroup, Banner, Paid from expobanner.models import URL, BannerGroup, Banner, Paid, MainPage, Top
from expobanner.forms import UrlCreateForm, BannerCreateGroupForm, BannerCreateForm, BannerGroupUpdateForm,\ from expobanner.forms import UrlCreateForm, BannerCreateGroupForm, BannerCreateForm, BannerGroupUpdateForm,\
PaidCreateForm, PaidUpdateForm, TopCreateForm PaidCreateForm, PaidUpdateForm, TopCreateForm, BannerLinkCreateForm, MainCreateForm, MainUpdateForm, TopUpdateForm
from exposition.models import Exposition from exposition.models import Exposition
@ -32,6 +32,10 @@ class CreateBanner(AbstractCreate):
model = Banner model = Banner
form_class = BannerCreateForm form_class = BannerCreateForm
class CreateLink(AbstractCreate):
model = Banner
form_class = BannerLinkCreateForm
# LISTS VIEWS # LISTS VIEWS
class AbstractList(ListView): class AbstractList(ListView):
@ -63,6 +67,16 @@ class BannerList(AbstractList):
qs = qs.filter(group__isnull=False) qs = qs.filter(group__isnull=False)
return qs 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 # UPDATE VIEWS
class AbstractUpdate(UpdateView): class AbstractUpdate(UpdateView):
template_name = 'admin/expobanner/default_form.html' template_name = 'admin/expobanner/default_form.html'
@ -84,10 +98,16 @@ class BannerUpdate(AbstractUpdate):
form_class = BannerCreateForm form_class = BannerCreateForm
class LinkUpdate(AbstractUpdate):
model = Banner
form_class = BannerLinkCreateForm
class BannerStat(DetailView): class BannerStat(DetailView):
model = Banner model = Banner
template_name = 'admin/expobanner/banner_stat.html' template_name = 'admin/expobanner/banner_stat.html'
class PaidList(ListView): class PaidList(ListView):
model = Exposition model = Exposition
template_name = 'admin/expobanner/paid_list.html' template_name = 'admin/expobanner/paid_list.html'
@ -96,11 +116,13 @@ class PaidList(ListView):
def get_queryset(self): def get_queryset(self):
return self.model.objects.language().filter(paid_new__isnull=False) return self.model.objects.language().filter(paid_new__isnull=False)
class PaidCreate(CreateView): class PaidCreate(CreateView):
form_class = PaidCreateForm form_class = PaidCreateForm
template_name = 'admin/expobanner/paid_create.html' template_name = 'admin/expobanner/paid_create.html'
success_url = '/admin/expobanners/paid/list/' success_url = '/admin/expobanners/paid/list/'
class PaidUpdate(UpdateView): class PaidUpdate(UpdateView):
model = Paid model = Paid
form_class = PaidUpdateForm form_class = PaidUpdateForm
@ -140,6 +162,52 @@ class PaidStat(DetailView):
model = Paid model = Paid
template_name = 'admin/expobanner/paid_stat.html' 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): class TopList(ListView):
model = Exposition model = Exposition
@ -154,3 +222,17 @@ class TopCreate(CreateView):
form_class = TopCreateForm form_class = TopCreateForm
template_name = 'admin/expobanner/top_create.html' template_name = 'admin/expobanner/top_create.html'
success_url = '/admin/expobanners/top/list/' 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

@ -8,13 +8,17 @@ urlpatterns = patterns('expobanner.admin',
url(r'^banners/url/$', CreateUrl.as_view(), name='expobanner-create_url'), url(r'^banners/url/$', CreateUrl.as_view(), name='expobanner-create_url'),
url(r'^banners/group/$', CreateBannerGroup.as_view(), name='expobanner-create_group'), url(r'^banners/group/$', CreateBannerGroup.as_view(), name='expobanner-create_group'),
url(r'^banners/banner/$', CreateBanner.as_view(), name='expobanner-create_banner'), url(r'^banners/banner/$', CreateBanner.as_view(), name='expobanner-create_banner'),
url(r'^banners/link/$', CreateLink.as_view(), name='expobanner-create_link'),
url(r'^banners/url/list/$', UrlList.as_view(), name='expobanner-list_url'), url(r'^banners/url/list/$', UrlList.as_view(), name='expobanner-list_url'),
url(r'^banners/group/list/$', BannerGroupList.as_view(), name='expobanner-list_group'), url(r'^banners/group/list/$', BannerGroupList.as_view(), name='expobanner-list_group'),
url(r'^banners/banner/list/$', BannerList.as_view(), name='expobanner-list_banner'), url(r'^banners/banner/list/$', BannerList.as_view(), name='expobanner-list_banner'),
url(r'^banners/link/list/$', LinkList.as_view(), name='expobanner-list_link'),
url(r'^banners/url/(?P<pk>\d+)/edit/$', UrlUpdate.as_view(), name='expobanner-update_url'), url(r'^banners/url/(?P<pk>\d+)/edit/$', UrlUpdate.as_view(), name='expobanner-update_url'),
url(r'^banners/group/(?P<pk>\d+)/edit/$', BannerGroupUpdate.as_view(), name='expobanner-update_group'), url(r'^banners/group/(?P<pk>\d+)/edit/$', BannerGroupUpdate.as_view(), name='expobanner-update_group'),
url(r'^banners/banner/(?P<pk>\d+)/edit/$', BannerUpdate.as_view(), name='expobanner-update_banner'), url(r'^banners/banner/(?P<pk>\d+)/edit/$', BannerUpdate.as_view(), name='expobanner-update_banner'),
url(r'^banners/link/(?P<pk>\d+)/edit/$', LinkUpdate.as_view(), name='expobanner-update_link'),
url(r'^banners/banner/(?P<pk>\d+)/stat/$', BannerStat.as_view(), name='expobanner_stat_banner'), url(r'^banners/banner/(?P<pk>\d+)/stat/$', BannerStat.as_view(), name='expobanner_stat_banner'),
url(r'^banners/banner/(?P<pk>\d+)/stat/$', BannerStat.as_view(), name='expobanner_stat_link'),
# paid # paid
url(r'^paid/list/$', PaidList.as_view(), name='expobanner-list_paid'), url(r'^paid/list/$', PaidList.as_view(), name='expobanner-list_paid'),
url(r'^paid/(?P<pk>\d+)/edit/$', PaidUpdate.as_view(), name='expobanner-update_paid'), url(r'^paid/(?P<pk>\d+)/edit/$', PaidUpdate.as_view(), name='expobanner-update_paid'),
@ -23,7 +27,13 @@ urlpatterns = patterns('expobanner.admin',
url(r'^paid/(?P<pk>\d+)/stat/$', PaidStat.as_view(), name='expobanner_stat_paid'), url(r'^paid/(?P<pk>\d+)/stat/$', PaidStat.as_view(), name='expobanner_stat_paid'),
# top # top
url(r'^top/list/$', TopList.as_view(), name='expobanner-list_top'), url(r'^top/list/$', TopList.as_view(), name='expobanner-list_top'),
url(r'^top/(?P<pk>\d+)/edit/$', PaidUpdate.as_view(), name='expobanner-update_top'), url(r'^top/(?P<pk>\d+)/edit/$', TopUpdate.as_view(), name='expobanner-update_top'),
url(r'^top/$', TopCreate.as_view(), name='expobanner-create_top'), url(r'^top/$', TopCreate.as_view(), name='expobanner-create_top'),
url(r'^top/(?P<pk>\d+)/stat/$', PaidStat.as_view(), name='expobanner_stat_top'), url(r'^top/(?P<pk>\d+)/stat/$', PaidStat.as_view(), name='expobanner_stat_top'),
# main page
url(r'^main/list/$', MainList.as_view(), name='expobanner-list_main'),
url(r'^main/(?P<pk>\d+)/edit/$', MainUpdate.as_view(), name='expobanner-update_main'),
url(r'^main/$', MainCreate.as_view(), name='expobanner-create_main'),
url(r'^main/turn/(?P<pk>\d+)/(?P<status>.*)/$', main_turn, name='expobanner-main-turn'),
url(r'^main/(?P<pk>\d+)/stat/$', MainStat.as_view(), name='expobanner_stat_main'),
) )

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django import forms from django import forms
from expobanner.models import URL, BannerGroup, Banner, Paid, Top from expobanner.models import URL, BannerGroup, Banner, Paid, Top, MainPage
from exposition.models import Exposition from exposition.models import Exposition
from country.models import Country from country.models import Country
from city.models import City from city.models import City
@ -9,6 +9,7 @@ from theme.models import Theme, Tag
class UrlCreateForm(forms.ModelForm): class UrlCreateForm(forms.ModelForm):
verbose = u'Создать урл' verbose = u'Создать урл'
class Meta: class Meta:
model = URL model = URL
exclude = ['created_at', 'updated_at', 'sites'] exclude = ['created_at', 'updated_at', 'sites']
@ -16,12 +17,14 @@ class UrlCreateForm(forms.ModelForm):
class BannerCreateGroupForm(forms.ModelForm): class BannerCreateGroupForm(forms.ModelForm):
verbose = u'Создать групу' verbose = u'Создать групу'
class Meta: class Meta:
model = BannerGroup model = BannerGroup
exclude = ['created_at', 'updated_at', 'speed'] exclude = ['created_at', 'updated_at', 'speed']
class BannerGroupUpdateForm(BannerCreateGroupForm): class BannerGroupUpdateForm(BannerCreateGroupForm):
verbose = u'Изменить групу' verbose = u'Изменить групу'
class Meta: class Meta:
model = BannerGroup model = BannerGroup
exclude = ['created_at', 'updated_at', 'slug', 'speed'] exclude = ['created_at', 'updated_at', 'slug', 'speed']
@ -29,15 +32,28 @@ class BannerGroupUpdateForm(BannerCreateGroupForm):
class BannerCreateForm(forms.ModelForm): class BannerCreateForm(forms.ModelForm):
verbose = u'Создать банер' verbose = u'Создать банер'
#country = forms.ChoiceField(label=u'Страна', choices=[('', ' ')] + [(c.id, c.name) for c in Country.objects.all()], required=False)
#theme = forms.ChoiceField(label=u'Тематика', required=False,
# choices=[('', ' ')] + [(item.id, item.name) for item in Theme.objects.language().all()])
#city = forms.CharField(label=u'Город', widget=forms.HiddenInput(), required=False)
#tag = forms.CharField(label=u'Тег', widget=forms.HiddenInput(), required=False)
class Meta: class Meta:
model = Banner model = Banner
exclude = ['created_at', 'updated_at', 'often', 'paid', 'stat_pswd'] exclude = ['created_at', 'updated_at', 'often', 'paid', 'stat_pswd', 'cookie', 'link']
class BannerLinkCreateForm(forms.ModelForm):
verbose = u'Отслеживаемую ссылку'
class Meta:
model = Banner
fields = ['public', 'alt', 'url']
exclude = ['created_at', 'updated_at', 'often', 'paid', 'stat_pswd', 'cookie', 'link']
def save(self, commit=True):
banner = super(BannerLinkCreateForm, self).save(commit=False)
if commit:
banner.link =True
banner.save()
return banner
class ClientStatForm(forms.Form): class ClientStatForm(forms.Form):
@ -91,6 +107,36 @@ class PaidCreateForm(forms.ModelForm):
raise forms.ValidationError(u'Такой выставки не существует') raise forms.ValidationError(u'Такой выставки не существует')
return expo return expo
class MainCreateForm(forms.ModelForm):
verbose = u'Добавить выставку на главную'
exposition = forms.CharField(label=u'Выставка', widget=forms.HiddenInput())
class Meta:
model = MainPage
fields = ['position', 'public']
def save(self, commit=True):
main = super(MainCreateForm, self).save(commit=False)
if commit:
expo = self.cleaned_data['exposition']
link = expo.get_permanent_url()
link_b = Banner.objects.create_for_paid(expo, link, 'main_page_link')
main.link = link_b
main.save()
expo.main = main
expo.save()
return main
def clean_exposition(self):
expo_id = self.cleaned_data['exposition']
try:
expo = Exposition.objects.get(id=expo_id)
except Exposition.DoesNotExist:
raise forms.ValidationError(u'Такой выставки не существует')
return expo
class PaidUpdateForm(forms.ModelForm): class PaidUpdateForm(forms.ModelForm):
tickets = forms.URLField(label=u'Линк на билеты') tickets = forms.URLField(label=u'Линк на билеты')
participation = forms.URLField(label=u'Линк на участие') participation = forms.URLField(label=u'Линк на участие')
@ -126,17 +172,23 @@ class PaidUpdateForm(forms.ModelForm):
return paid return paid
class MainUpdateForm(forms.ModelForm):
class Meta:
model = MainPage
fields = ['position', 'public']
class TopCreateForm(forms.ModelForm): class TopCreateForm(forms.ModelForm):
verbose = u'Создать выставку в топе' verbose = u'Создать выставку в топе'
exposition = forms.CharField(label=u'Выставка', widget=forms.HiddenInput()) exposition = forms.CharField(label=u'Выставка', widget=forms.HiddenInput())
country = forms.MultipleChoiceField(label=u'Страна', choices=[('', ' ')] + [(c.id, c.name) for c in Country.objects.all()], required=False) country = forms.MultipleChoiceField(label=u'Страна', choices=[('', ' ')] + [(c.id, c.name) for c in Country.objects.all()], required=False)
theme = forms.MultipleChoiceField(label=u'Тематика', required=False, theme = forms.MultipleChoiceField(label=u'Тематика', required=False,
choices=[('', ' ')] + [(item.id, item.name) for item in Theme.objects.language().all()]) choices=[('', ' ')] + [(item.id, item.name) for item in Theme.objects.language().all()])
excluded_cities = forms.CharField(label=u'Город', widget=forms.HiddenInput(), required=False) #excluded_cities = forms.CharField(label=u'Город', widget=forms.HiddenInput(), required=False)
excluded_tags = forms.CharField(label=u'Тег', widget=forms.HiddenInput(), required=False) #excluded_tags = forms.CharField(label=u'Тег', widget=forms.HiddenInput(), required=False)
class Meta: class Meta:
model = Top model = Top
fields = ['catalog', 'position', 'theme', 'excluded_tags', 'country', 'excluded_cities', 'fr', 'to'] fields = ['catalog', 'position', 'theme', 'country', 'fr', 'to']
def save(self, commit=True): def save(self, commit=True):
top = super(TopCreateForm, self).save(commit=False) top = super(TopCreateForm, self).save(commit=False)
@ -149,6 +201,9 @@ class TopCreateForm(forms.ModelForm):
top.theme.clear() top.theme.clear()
for theme in self.cleaned_data['theme']: for theme in self.cleaned_data['theme']:
top.theme.add(theme) top.theme.add(theme)
top.country.clear()
for country in self.cleaned_data['country']:
top.country.add(country)
self.save_m2m = save_m2m self.save_m2m = save_m2m
@ -179,3 +234,33 @@ class TopCreateForm(forms.ModelForm):
except Exposition.DoesNotExist: except Exposition.DoesNotExist:
raise forms.ValidationError(u'Такой выставки не существует') raise forms.ValidationError(u'Такой выставки не существует')
return expo return expo
class TopUpdateForm(forms.ModelForm):
verbose = u'Изменить выставку'
class Meta:
model = Top
fields = ['catalog', 'position', 'theme', 'country', 'fr', 'to']
def save(self, commit=True):
top = super(TopUpdateForm, self).save(commit=False)
# Prepare a 'save_m2m' method for the form,
old_save_m2m = self.save_m2m
def save_m2m():
old_save_m2m()
# This is where we actually link the pizza with toppings
top.theme.clear()
for theme in self.cleaned_data['theme']:
top.theme.add(theme)
top.country.clear()
for country in self.cleaned_data['country']:
top.country.add(country)
self.save_m2m = save_m2m
if commit:
top.save()
self.save_m2m()
return top

@ -9,7 +9,7 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
today = date.today() today = date.today()
# banners # banners
for banner in Banner.objects.select_related('group').filter(public=True, group__isnull=False): for banner in Banner.objects.select_related('group').filter(public=True):
try: try:
logstat = LogStat.objects.get(banner=banner, group=banner.group, date=today) logstat = LogStat.objects.get(banner=banner, group=banner.group, date=today)
except LogStat.DoesNotExist: except LogStat.DoesNotExist:

@ -51,7 +51,7 @@ class BannerGroupCached(models.Manager):
for group in groups: for group in groups:
result[group.slug] = list(group.banners.prefetch_related('urls', 'theme', 'country')\ result[group.slug] = list(group.banners.prefetch_related('urls', 'theme', 'country')\
.filter(public=True, fr__lte=today)\ .filter(public=True, fr__lte=today)\
.filter(Q(to__gte=today) | Q(to__isnull=True)).extra({})) .filter(Q(to__gte=today) | Q(to__isnull=True)))
cache.set(key, result, 70) cache.set(key, result, 70)
return result return result
@ -71,7 +71,9 @@ class TopCached(models.Manager):
key = 'expo_b_top_all' key = 'expo_b_top_all'
result = cache.get(key) result = cache.get(key)
if not result: if not result:
result = list(self.prefetch_related('theme', 'country', 'excluded_tags', 'excluded_cities').all()) today = date.today()
result = list(self.prefetch_related('theme', 'country', 'excluded_tags', 'excluded_cities').
filter(fr__lte=today).filter(Q(to__gte=today) | Q(to__isnull=True)))
cache.set(key, result, 80) cache.set(key, result, 80)
return result return result

@ -97,6 +97,7 @@ class Banner(models.Model, StatMixin):
flash = models.BooleanField(verbose_name=_('Flash?'), default=False) flash = models.BooleanField(verbose_name=_('Flash?'), default=False)
popup = models.BooleanField(verbose_name=_('Popup?'), default=False) popup = models.BooleanField(verbose_name=_('Popup?'), default=False)
paid = models.BooleanField(verbose_name=_('Is Paid event link?'), default=False) paid = models.BooleanField(verbose_name=_('Is Paid event link?'), default=False)
link = models.BooleanField(verbose_name=_('Is simple link?'), default=False)
# for detecting popups # for detecting popups
cookie = models.CharField(max_length=30, blank=True, null=True, default=settings.DEFAULT_POPUP_COOKIE) cookie = models.CharField(max_length=30, blank=True, null=True, default=settings.DEFAULT_POPUP_COOKIE)
@ -223,9 +224,10 @@ class Paid(models.Model, StatMixin):
ordering = ['-public'] ordering = ['-public']
def get_event(self): def get_event(self):
if self.exposition_set.all().exists(): try:
return self.exposition_set.all()[0] return self.exposition_set.all()[0]
return None except IndexError:
return None
class PaidStat(models.Model): class PaidStat(models.Model):
@ -272,6 +274,25 @@ class TopStat(models.Model):
views = models.PositiveIntegerField(default=0) views = models.PositiveIntegerField(default=0)
clicks = models.PositiveIntegerField(default=0) clicks = models.PositiveIntegerField(default=0)
class MainPage(models.Model, StatMixin):
link = models.ForeignKey(Banner)
position = models.PositiveIntegerField(blank=True, default=2, null=True, verbose_name=u'Позиция')
public = models.BooleanField(default=True, verbose_name=u'Активная')
stat_pswd = models.CharField(max_length=16)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
class Meta:
ordering = ['-public']
def get_event(self):
try:
return self.exposition_set.all()[0]
except IndexError:
return None
def generatePassword(length=5): def generatePassword(length=5):
""" """
generate random password generate random password

@ -44,7 +44,12 @@ def get_banners(request):
result = [] result = []
set_cookie = None set_cookie = None
# get banners for all groups # get banners for all groups
places = request.GET.getlist('places', [])
for group, banners in group_banners.iteritems(): for group, banners in group_banners.iteritems():
if group not in places:
# on this page there is no such group
continue
banner = get_banner_by_params(banners, good_urls, params, request) banner = get_banner_by_params(banners, good_urls, params, request)
if banner: if banner:
if banner.html: if banner.html:

@ -10,6 +10,7 @@ class ClientManager(TranslationManager):
def upcoming(self): def upcoming(self):
return self.filter(data_begin__gte=datetime.datetime.now().date()) return self.filter(data_begin__gte=datetime.datetime.now().date())
""" """
from exposition.models import Exposition from exposition.models import Exposition

@ -158,6 +158,7 @@ class Exposition(TranslatableModel, EventMixin, ExpoMixin):
paid_new = models.ForeignKey('expobanner.Paid', blank=True, null=True, on_delete=models.SET_NULL) 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) 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) #set manager of this model(fisrt manager is default)
objects = ExpoManager() objects = ExpoManager()
enable = ClientManager() enable = ClientManager()
@ -306,6 +307,12 @@ class Exposition(TranslatableModel, EventMixin, ExpoMixin):
def theme_ids(self): def theme_ids(self):
return [item['id'] for item in self.theme.all().values('id')] 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()
class Statistic(TranslatableModel): class Statistic(TranslatableModel):
exposition = models.ForeignKey(Exposition, related_name='statistic') exposition = models.ForeignKey(Exposition, related_name='statistic')

@ -25,6 +25,17 @@ class ExpoManager(TranslationManager):
except: except:
return None return None
def expo_main(self):
lang = translation.get_language()
key = 'expo_main_page_key_%s'%lang
result = cache.get(key)
if not result:
result = list(self.language(lang).select_related('country', 'city', 'place', 'main').prefetch_related('tag').filter(main__isnull=False))
cache.set(key, result, 45)
return result
class CityManager(TranslationManager): class CityManager(TranslationManager):
cache_time = 600 cache_time = 600

@ -77,8 +77,11 @@ class MainPageView(JitterCacheMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(MainPageView, self).get_context_data(**kwargs) context = super(MainPageView, self).get_context_data(**kwargs)
ev = Exposition.objects.expo_main()
events = Exposition.objects.language().select_related('country', 'city', 'place').filter(main_page__gte=1).order_by('-main_page') events = sorted(ev, key=lambda x: x.main.position)
# update main_page counter
for event in events:
event.main.link.log(self.request, 1)
exposition_themes = Theme.objects.language().order_by('-main_page').filter(types=Theme.types.exposition)[:6] exposition_themes = Theme.objects.language().order_by('-main_page').filter(types=Theme.types.exposition)[:6]
conference_themes = Theme.objects.language().order_by('-main_page').filter(types=Theme.types.conference)[:6] conference_themes = Theme.objects.language().order_by('-main_page').filter(types=Theme.types.conference)[:6]

@ -13,6 +13,9 @@
<div class="span4"><h6><a href="{% url 'expobanner-create_group' %}">Групы</a></h6></div> <div class="span4"><h6><a href="{% url 'expobanner-create_group' %}">Групы</a></h6></div>
<div class="span4"><h6><a href="{% url 'expobanner-create_banner' %}">Банера</a></h6></div> <div class="span4"><h6><a href="{% url 'expobanner-create_banner' %}">Банера</a></h6></div>
</div> </div>
<div class="row-fluid">
<div class="span4"><h6><a href="{% url 'expobanner-create_link' %}">Отслеживаемой ссылки</a></h6></div>
</div>
</div> </div>
</div><!--/span--> </div><!--/span-->
@ -27,6 +30,9 @@
<div class="span4"><h6><a href="{% url 'expobanner-list_group' %}">Груп</a></h6></div> <div class="span4"><h6><a href="{% url 'expobanner-list_group' %}">Груп</a></h6></div>
<div class="span4"><h6><a href="{% url 'expobanner-list_banner' %}">Банеров</a></h6></div> <div class="span4"><h6><a href="{% url 'expobanner-list_banner' %}">Банеров</a></h6></div>
</div> </div>
<div class="row-fluid">
<div class="span4"><h6><a href="{% url 'expobanner-list_link' %}">Отслеживаемых ссылок</a></h6></div>
</div>
</div> </div>
</div><!--/span--> </div><!--/span-->
</div> </div>

@ -0,0 +1,38 @@
{% extends 'base.html' %}
{% block body %}
<div class="box span8">
<div class="box-header well">
<h2><i class="icon-arrow-down"></i>{{ verbose }}</h2>
</div>
<div class="box-content">
{% block list_table %}
<table class="table table-hover">
<thead>
<tr>
<th>Объект</th>
<th>ссылка для отслеживания</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{% for item in object_list %}
<tr>
<td>{{ item }}</td>
<td>{{request.get_host}}{{ item.get_click_link }}</td>
<td><a href="{% url 'expobanner-update_link' item.id %}">Изменить</a> </td>
<td><a href="{% url 'expobanner_stat_link' item.id %}">Статистика</a> </td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
</div>
{# pagination #}
{% include 'admin/includes/admin_pagination.html' with page_obj=object_list %}
</div>
{% endblock %}

@ -0,0 +1,38 @@
{% extends 'base.html' %}
{% block body %}
<div class="box span8">
<div class="box-header well">
<h2><i class="icon-arrow-down"></i>Список выставок на главной</h2>
</div>
<div class="box-content">
{% block list_table %}
<a class="btn btn-success" href="{% url 'expobanner-create_main' %}"><i class="icon-plus-sign icon-white"></i> Добавить выставку</a>
<table class="table table-hover">
<thead>
<tr>
<th>Выставка</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{% for item in object_list %}
<tr>
<td>{{ item }}</td>
<td><a href="{% url 'expobanner-update_main' item.main.id %}">Изменить</a> </td>
<td>{% if item.main.public %}<a href="{% url 'expobanner-main-turn' item.main.id 'off' %}">отключить</a>{% else %}<a href="{% url 'expobanner-main-turn' item.main.id 'on' %}">включить</a>{% endif %} </td>
<td><a href="{% url 'expobanner_stat_main' item.main.id %}">Статистика</a> </td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
</div>
{# pagination #}
{% include 'admin/includes/admin_pagination.html' with page_obj=object_list %}
</div>
{% endblock %}

@ -61,7 +61,7 @@ $(function(){
<fieldset> <fieldset>
<div class="box span8"> <div class="box span8">
<div class="box-header well"> <div class="box-header well">
<h2><i class="icon-pencil"></i>{{ form.verbose }}</h2> <h2><i class="icon-pencil"></i>{{ form.verbose }} {% if object %}{{ object.get_event }}{% endif %}</h2>
</div> </div>
<div class="box-content"> <div class="box-content">
{% for field in form %} {% for field in form %}

@ -78,16 +78,7 @@ This template include basic anf main styles and js files,
}); });
</script> </script>
<!--test expo_b -->
<script>
window.sendData = {
"theme": [{{ themes|join:", " }}],
"country": "{{ country }}",
"city": "{{ city }}",
"tag": "{{ tag }}"
};
</script>
<script type="text/javascript" src="{% static 'client/js/rejs/banners.js' %}"></script>
</head> </head>
<body {% block body_class %}{% endblock %}> <body {% block body_class %}{% endblock %}>
@ -237,5 +228,20 @@ This template include basic anf main styles and js files,
<script src="{% static 'client/js_min/vendor.min.js' %}"></script> <script src="{% static 'client/js_min/vendor.min.js' %}"></script>
{% endif %} {% endif %}
<div id="wait-ajax" class="wait-ajax" style="display:none;"><img src="{% static 'client/img/ajax-loader.gif' %}" alt=""/></div> <div id="wait-ajax" class="wait-ajax" style="display:none;"><img src="{% static 'client/img/ajax-loader.gif' %}" alt=""/></div>
<!--test expo_b -->
<script>
var places_ids = [];
var divs = $('[id^="expo_b_"]');
for(var i=0; i<divs.length; i++){places_ids.push($(divs[i]).attr('id'))}
window.sendData = {
"theme": [{{ themes|join:", " }}],
"country": "{{ country }}",
"city": "{{ city }}",
"tag": "{{ tag }}",
"places": places_ids
};
</script>
<script type="text/javascript" src="{% static 'client/js/rejs/banners.js' %}"></script>
</body> </body>

@ -12,7 +12,7 @@
<li class="swiper-slide"> <li class="swiper-slide">
<div class="re-pict pict-over" > <div class="re-pict pict-over" >
{% if event.logo %} {% if event.logo %}
<a href="{{ event.get_permanent_url }}"> <a href="{{ event.get_main_link }}">
<!--<img src="{{ event.logo.url }}">--> <!--<img src="{{ event.logo.url }}">-->
{% thumbnail event.get_preview "220x220" as im %} {% thumbnail event.get_preview "220x220" as im %}
@ -24,7 +24,7 @@
</div> </div>
<div class="re-body"> <div class="re-body">
<div class="re-info"> <div class="re-info">
<a href="{{ event.get_permanent_url }}"> <a href="{{ event.get_main_link }}">
<div class="re-title">{{ event.name|safe }}</div> <div class="re-title">{{ event.name|safe }}</div>
<div class="re-date"> <div class="re-date">
{% include 'client/includes/index/main_date_block.html' with obj=event %} {% include 'client/includes/index/main_date_block.html' with obj=event %}

Loading…
Cancel
Save