ExpoBanner. Finale

remotes/origin/1203
Kotiuk Nazarii 11 years ago
parent 3450aa0968
commit 6b94fc665d
  1. 8
      expobanner/admin.py
  2. 8
      expobanner/forms.py
  3. 1
      expobanner/models.py
  4. 56
      expobanner/utils.py
  5. 21
      expobanner/views.py
  6. 8
      exposition/forms.py
  7. 6
      exposition/models.py
  8. 4
      exposition/views.py
  9. 1
      proj/urls.py
  10. 22
      settings/views.py
  11. 1
      templates/admin/expobanner/default_form.html
  12. 2
      templates/admin/expobanner/link_list.html
  13. 2
      templates/admin/expobanner/main_list.html
  14. 48
      templates/admin/expobanner/main_stat.html
  15. 4
      templates/admin/expobanner/paid_stat.html
  16. 1
      templates/admin/includes/admin_nav.html
  17. 2
      templates/client/base_catalog.html
  18. 69
      templates/client/blank.html
  19. 28
      templates/client/expobanners/banner_stat.html
  20. 30
      templates/client/expobanners/paid_stat.html
  21. 71
      templates/client/exposition/exposition_detail.html
  22. 2
      templates/client/includes/banners/popup.html
  23. 6
      templates/client/includes/exposition/expo_top.html

@ -204,7 +204,13 @@ def main_turn(request, pk, status):
class MainStat(DetailView):
model = MainPage
template_name = 'admin/expobanner/paid_stat.html'
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()
return context
# ------------------------------------

@ -3,7 +3,7 @@ from django import forms
from expobanner.models import URL, BannerGroup, Banner, Paid, Top, MainPage
from exposition.models import Exposition
from country.models import Country
from city.models import City
from ckeditor.widgets import CKEditorWidget
from theme.models import Theme, Tag
@ -32,7 +32,7 @@ class BannerGroupUpdateForm(BannerCreateGroupForm):
class BannerCreateForm(forms.ModelForm):
verbose = u'Создать банер'
text = forms.CharField(label=u'Текст', required=False, widget=CKEditorWidget)
class Meta:
model = Banner
exclude = ['created_at', 'updated_at', 'often', 'paid', 'stat_pswd', 'cookie', 'link']
@ -209,10 +209,14 @@ class TopCreateForm(forms.ModelForm):
if commit:
expo = self.cleaned_data['exposition']
link = expo.get_permanent_url()
link_b = Banner.objects.create_for_paid(expo, link, 'top_link')
top.link = link_b
top.save()
self.save_m2m()
expo.top = top
expo.save()
return top
def clean_theme(self):

@ -243,6 +243,7 @@ class PaidStat(models.Model):
class Top(models.Model, StatMixin):
link = models.ForeignKey(Banner)
catalog = models.CharField(max_length=16, verbose_name=u'Каталог для топа')
position = models.PositiveIntegerField(blank=True, default=2, null=True, verbose_name=u'Позиция')
theme = models.ManyToManyField('theme.Theme', blank=True, null=True, verbose_name=u'Тематики')

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
import re
import random
import datetime
from django.db import connection
def get_client_ip(request):
@ -10,6 +12,32 @@ def get_client_ip(request):
ip = request.META.get('REMOTE_ADDR')
return ip
def get_referer_view(request, default=None):
'''
Return the referer view of the current request
Example:
def some_view(request):
...
referer_view = get_referer_view(request)
return HttpResponseRedirect(referer_view, '/accounts/login/')
'''
# if the user typed the url directly in the browser's address bar
referer = request.META.get('HTTP_REFERER')
if not referer:
return default
# remove the protocol and split the url at the slashes
referer = re.sub('^https?:\/\/', '', referer).split('/')
if referer[0] != request.META.get('SERVER_NAME'):
return default
# add the slash at the relative path's view and finished
referer = u'/' + u'/'.join(referer[1:])
return referer
def get_by_sort(banner_list):
max_sort = 0
for banner in banner_list:
@ -19,6 +47,15 @@ def get_by_sort(banner_list):
result = [banner for banner in banner_list if banner.sort == max_sort]
return result
def set_cookie(response, key, value, days_expire = 7):
if days_expire is None:
max_age = 365 * 24 * 60 * 60 #one year
else:
max_age = days_expire * 24 * 60 * 60
expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=max_age), "%a, %d-%b-%Y %H:%M:%S GMT")
response.set_cookie(key, value, max_age=max_age, expires=expires)
return response
def get_banner_by_params(banners_list, urls, params, request):
thematic_banners = []
@ -69,14 +106,18 @@ def get_banner_by_params(banners_list, urls, params, request):
continue
if thematic_banners:
return random.choice(thematic_banners)
if url_banners:
return random.choice(url_banners)
return None
#print('END. NUMBER of queries = %d'%len(connection.queries))
result = thematic_banners
elif url_banners:
result = url_banners
else:
result = []
if result:
sort_result = get_by_sort(result)
return random.choice(sort_result)
else:
return None
def get_top_events(tops, params):
def get_top_events(tops, params, request):
catalog = params.get('catalog')
country = params.get('country', '')
theme = params.get('theme', [])
@ -113,5 +154,6 @@ def get_top_events(tops, params):
for top in sorted_top:
event = top.get_event()
if event:
top.link.log(request, 1)
events.append(event)
return events

@ -6,7 +6,7 @@ from django.shortcuts import redirect, get_object_or_404
from django.shortcuts import render_to_response
from django.template import RequestContext
from .models import Banner, BannerGroup, URL, Top
from expobanner.utils import get_by_sort, get_banner_by_params, get_client_ip, get_top_events
from expobanner.utils import get_banner_by_params, get_client_ip, get_top_events, get_referer_view, set_cookie
def click(request, banner_id):
@ -21,8 +21,7 @@ def view(request, banner_id):
return redirect(banner.img.url)
def get_banners(request):
#url = request.GET.get('url', '/')
url = request.META.get('HTTP_REFERER', '/')
url = get_referer_view(request, default='/')
# get urls by current url
urls = URL.cached.all()
good_urls = []
@ -42,7 +41,7 @@ def get_banners(request):
group_banners = BannerGroup.cached.group_banners()
result = []
set_cookie = None
cookie = None
# get banners for all groups
places = request.GET.getlist('places', [])
@ -59,7 +58,10 @@ def get_banners(request):
is_img = False
else:
text = ''
img = banner.img.url
try:
img = banner.img.url
except ValueError:
continue
alt = banner.alt
is_img = True
result.append({'id': group,
@ -73,12 +75,13 @@ def get_banners(request):
'text': text
})
if banner.popup:
set_cookie = banner.cookie
cookie = banner.cookie
# add view log
banner.log(request, 1)
response = HttpResponse(json.dumps(result, indent=4), content_type='application/json')
if set_cookie:
response.set_cookie(set_cookie, 1)
if cookie:
response = set_cookie(response, cookie, '1')
return response
def get_top(request):
@ -89,6 +92,6 @@ def get_top(request):
'catalog': request.GET.get('catalog')}
tops = Top.cached.all()
events = get_top_events(tops, params)
events = get_top_events(tops, params, request)
context = {'objects': events}
return render_to_response('client/includes/exposition/expo_top.html', context, context_instance=RequestContext(request))

@ -2,8 +2,6 @@
from django import forms
from django.conf import settings
from ckeditor.widgets import CKEditorWidget
from tinymce.widgets import TinyMCE
from django.core.exceptions import ValidationError
from django.forms.util import ErrorList
from django.core.validators import validate_email, URLValidator
from django.utils.translation import ugettext as _
@ -13,15 +11,11 @@ from theme.models import Tag
from country.models import Country
from theme.models import Theme
from organiser.models import Organiser
from accounts.models import User
from company.models import Company
from city.models import City
from service.models import Service
from place_exposition.models import PlaceExposition
#functions
from functions.translate import populate_all, fill_trans_fields_all, fill_with_signal
from functions.translate import fill_with_signal
from functions.form_check import is_positive_integer
from functions.files import check_tmp_files
from functions.form_check import translit_with_separator
from settings.settings import date_formats
from functions.admin_forms import AdminFilterForm

@ -313,6 +313,12 @@ class Exposition(TranslatableModel, EventMixin, ExpoMixin):
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')

@ -433,7 +433,9 @@ class ExpoCityCatalog(ExpoCatalog):
return qs
def get_context_data(self, **kwargs):
context = super(ExpoCityCatalog, self).get_context_data(**kwargs)
context['city'] = str(self.kwargs['city'].id)
city = self.kwargs['city']
context['country'] = str(city.country_id)
context['city'] = str(city.id)
return context

@ -78,7 +78,6 @@ urlpatterns = patterns('',
# ajax urls
urlpatterns += patterns('',
url(r'^ajax/get_popover/$', 'settings.views.get_popover_info'),
url(r'^registration/reply/$', 'registration.backends.default.views.RegisterReply'),
url(r'^register/', 'registration.backends.default.views.RegisterAjaxView'),
url(r'^register-complete/', 'registration.backends.default.views.complete_registration'),

@ -159,24 +159,4 @@ def get_popover(request):
html = render_to_string(popover)
response['html'] = html
return HttpResponse(json.dumps(response), content_type='application/json')
from banners.models import Redirect
from django.db.models import F
import datetime
def set_cookie(response, key, value, days_expire = 7):
if days_expire is None:
max_age = 365 * 24 * 60 * 60 #one year
else:
max_age = days_expire * 24 * 60 * 60
expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=max_age), "%a, %d-%b-%Y %H:%M:%S GMT")
response.set_cookie(key, value, max_age=max_age, expires=expires)
def get_popover_info(request):
id = request.GET.get('rdr')
if id:
Redirect.objects.filter(id=id).update(views = F('views') + 1)
response = HttpResponse('success')
set_cookie(response, 'popover_test1', '1')
return response
return HttpResponse(json.dumps(response), content_type='application/json')

@ -2,6 +2,7 @@
{% load static %}
{% block scripts %}
<script src="{% static 'ckeditor/ckeditor/ckeditor.js' %}"></script>
<link href="{% static 'js/select/select2.css' %}" rel="stylesheet"/>
<script src="{% static 'js/select/select2.js' %}"></script>
<script>

@ -22,7 +22,7 @@
{% for item in object_list %}
<tr>
<td>{{ item }}</td>
<td>{{request.get_host}}{{ item.get_click_link }}</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>

@ -13,6 +13,7 @@
<thead>
<tr>
<th>Выставка</th>
<th>Позиция</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
@ -22,6 +23,7 @@
{% for item in object_list %}
<tr>
<td>{{ item }}</td>
<td>{{ item.main.position }}</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>

@ -0,0 +1,48 @@
{% extends 'base.html' %}
{% load static %}
{% block scripts %}
<script src="{% static 'js/jquery.dataTables.min.js' %}"></script>
{% endblock %}
{% block body %}
<div class="row-fluid sortable">
<div class="box span12">
<div class="box-header well" data-original-title>
<h2><i class="icon-align-justify"></i> {{ object.get_event }}</h2>
</div>
<div class="box-content">
<div class="row-fluid">
<div class="span8">Линк на статистику: <b>{{ request.get_host }}/expo-b/banner/{{ object.link.id }}/stat/</b></div>
<div class="span4">Пароль: <b>{{ object.link.stat_pswd }}</b></div>
</div>
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>Дата</th>
<th>Показы</th>
<th>Клики</th>
<th>Уникальные показы</th>
<th>Уникальные клики</th>
</tr>
</thead>
<tbody>
{% with stats=stats %}
{% for stat in stats %}
<tr>
<td>{{ stat.date|date:"Y-m-d" }}</td>
<td>{{ stat.view }}</td>
<td>{{ stat.click }}</td>
<td>{{ stat.unique_view }}</td>
<td>{{ stat.unique_click }}</td>
</tr>
{% endfor %}
{% endwith %}
</tbody>
</table>
</div>
</div>
</div>
{% endblock %}

@ -12,6 +12,10 @@
<h2><i class="icon-align-justify"></i> {{ object.get_event }} (Пароль: {{ object.stat_pswd }})</h2>
</div>
<div class="box-content">
<div class="row-fluid">
<div class="span8">Линк на статистику: <b>{{ request.get_host }}/expo-b/paid/{{ object.id }}/stat/</b></div>
<div class="span4">Пароль: <b>{{ object.stat_pswd }}</b></div>
</div>
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>

@ -111,6 +111,7 @@
<li><a href="/admin/expobanners/banners/control/">Управление банерами</a></li>
<li><a href="/admin/expobanners/paid/list/">Платные выставки</a></li>
<li><a href="/admin/expobanners/top/list/">Выставки в топе</a></li>
<li><a href="/admin/expobanners/main/list/">Выставки на главной</a></li>
</ul>
</li>

@ -1,4 +1,4 @@
{% extends 'blank.html' %}
{% extends 'client/blank.html' %}
{% load static %}
{% load i18n %}

@ -129,75 +129,6 @@ This template include basic anf main styles and js files,
{% include 'client/popups/callback.html' %}
{% include 'client/includes/banners/popup.html' %}
{% block popup_banner %}
{% if not request.COOKIES.popover_test1 %}
{% if theme_for_filter %}
{% if theme_for_filter.id == 54 or theme_for_filter.id == 26 or theme_for_filter.id == 22 or theme_for_filter.id == 15 or theme_for_filter.id == 44 or theme_for_filter.id == 30 %}
{% with r=False|random3 %}
{% if r == 1 %}
{% include 'client/popups/cemat_modal.html' %}
{% else %}
{% if r == 2 %}
{% include 'client/popups/cemat_banner1.html' %}
{% else %}
{% include 'client/popups/cemat_banner2.html' %}
{% endif %}
{% endif %}
{% endwith %}
{% endif %}
{% if theme_for_filter.id == 32 %}
{% with r=False|random3 %}
{% if r == 1 %}
{% include 'client/popups/cemat_modal.html' %}
{% endif %}
{% if r == 2 %}
{% include 'client/popups/cemat_banner1.html' %}
{% endif %}
{% if r == 0 %}
{% include 'client/popups/cemat_banner2.html' %}
{% endif %}
{% endwith %}
{% endif %}
<script>
$(function() {
if ($('#expo-ad-popup').length > 0){
$('#expo-form-popup').on('submit', function(e){
e.preventDefault();
var link = $('#expo-form-popup').attr('action');
window.location = link;
});
setTimeout(function(){
$.fancybox.open(
[{href: '#expo-ad-popup'}],
{}
);
var rdr = $('#expo-ad-popup').attr('data-rdr');
sendData = {'rdr': rdr};
console.log(rdr);
$.ajax({
url: '/ajax/get_popover/',
data: sendData,
type: 'GET',
async: true,
success: function(data){
console.log(data);
}
});
}, 5000);
}
});
</script>
{% endif %}
{% endif %}
{% endblock %}
{# if user doesnt have url- show form #}
{% if 'partial_pipeline' not in request.session %}

@ -1,5 +1,33 @@
{% extends 'base_catalog.html' %}
{% block styles %}
<style>
table {
width: 100%;
margin-bottom: 18px;
border: 1px solid #dddddd;
border-collapse: separate;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
border-spacing: 2px;
border-color: grey;
}
table th{
vertical-align: bottom;
font-weight: bold;
text-align: left;
}
table th. table td{
padding: 8px;
line-height: 18px;
text-align: left;
display: table-cell;
}
</style>
{% endblock %}
{% block page_title %}
<div class="page-title">
<h1>{{ object }}. Статистика</h1>

@ -1,4 +1,32 @@
{% extends 'base_catalog.html' %}
{% extends 'client/base_catalog.html' %}
{% block styles %}
<style>
table {
width: 100%;
margin-bottom: 18px;
border: 1px solid #dddddd;
border-collapse: separate;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
border-spacing: 2px;
border-color: grey;
}
table th{
vertical-align: bottom;
font-weight: bold;
text-align: left;
}
table th. table td{
padding: 8px;
line-height: 18px;
text-align: left;
display: table-cell;
}
</style>
{% endblock %}
{% block page_title %}
<div class="page-title">

@ -26,73 +26,4 @@
{% block paginator %}
{% endblock %}
{% block popup%}
{% if not request.COOKIES.popover_test1 %}
{% with theme_ids=object.theme_ids %}
{% if 32 in theme_ids %}
{% with r=False|random3 %}
{% if r == 0 %}
{% include 'client/popups/cemat_modal.html' %}
{% endif %}
{% if r == 1 %}
{% include 'client/popups/cemat_banner1.html' %}
{% endif %}
{% if r == 2 %}
{% include 'client/popups/cemat_banner2.html' %}
{% endif %}
{% endwith %}
{% else %}
{% if 54 in theme_ids or 26 in theme_ids or 22 in theme_ids or 15 in theme_ids or 44 in theme_ids or 30 in theme_ids %}
{% with r=False|random3 %}
{% if r == 1 %}
{% include 'client/popups/cemat_modal.html' %}
{% else %}
{% if r == 2 %}
{% include 'client/popups/cemat_banner1.html' %}
{% else %}
{% include 'client/popups/cemat_banner2.html' %}
{% endif %}
{% endif %}
{% endwith %}
{% endif %}
{% endif %}
{% endwith %}
<script>
$(function() {
if ($('#expo-ad-popup').length > 0){
$('#expo-form-popup').on('submit', function(e){
e.preventDefault();
var link = $('#expo-form-popup').attr('action');
window.location = link;
});
setTimeout(function(){
$.fancybox.open(
[{href: '#expo-ad-popup'}],
{}
);
var rdr = $('#expo-ad-popup').attr('data-rdr');
sendData = {'rdr': rdr};
$.ajax({
url: '/ajax/get_popover/',
data: sendData,
type: 'GET',
async: true,
success: function(data){
console.log(data);
}
});
}, 5000);
}
});
</script>
{% endif %}
{% endblock %}
{% endblock %}

@ -1,2 +1,2 @@
<div id="expo_b_popup" class="popup-window" style="width:800px;">
<div id="expo_b_popup" class="popup-window" style="width:900px;">
</div>

@ -5,10 +5,10 @@
<ul class="cat-list cl-exhibitions">
{% for obj in objects %}
<li class="cl-item {% if obj.canceled %}canceled{% endif %}">
<li class="cl-item {% if obj.canceled %}canceled{% endif %}" style="border:1px solid #ff6600;">
<div class="cl-item-wrap clearfix">
{% if not obj.canceled %}
<a href="{% if not obj.paid_new_id %}{{ obj.get_permanent_url }}{% else %}{{ obj.get_paid_catalog_url }}{% endif %}">
<a href="{{ obj.get_top_link }}">
{% if obj.expohit %}
<div class="hit"></div>
{% endif %}
@ -35,7 +35,7 @@
</div>
{% endif %}
<header>
<div class="cli-title"><a href="{% if not obj.paid_new_id %}{{ obj.get_permanent_url }}{% else %}{{ obj.get_paid_catalog_url }}{% endif %}">{{ obj.name|safe }}</a></div>
<div class="cli-title"><a href="{{ obj.get_top_link }}">{{ obj.name|safe }}</a></div>
</header>
<div class="cli-descr">
{{ obj.main_title|safe }}

Loading…
Cancel
Save