diff --git a/banners/models.py b/banners/models.py index b9779288..8cd34977 100644 --- a/banners/models.py +++ b/banners/models.py @@ -5,6 +5,8 @@ from django.db import models class Redirect(models.Model): redirect = models.URLField() count = models.PositiveIntegerField(default=0) + views = models.PositiveIntegerField(default=0) + def __unicode__(self): return self.redirect diff --git a/proj/urls.py b/proj/urls.py index 92cf2c80..c73029c6 100644 --- a/proj/urls.py +++ b/proj/urls.py @@ -79,6 +79,7 @@ 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'), diff --git a/settings/templatetags/template_filters.py b/settings/templatetags/template_filters.py index ad5276dd..b013912e 100644 --- a/settings/templatetags/template_filters.py +++ b/settings/templatetags/template_filters.py @@ -160,6 +160,10 @@ def random_social(value): def random3(value): return random.randrange(0,3) +@register.filter +def random5(value): + return random.randrange(0,5) + @register.filter def fourth(value): # return almost in 75% cases True in 25% False diff --git a/settings/views.py b/settings/views.py index 8c2e72cc..a2d22475 100644 --- a/settings/views.py +++ b/settings/views.py @@ -124,4 +124,52 @@ def company_autosearch(request): result = sorted(result, key=lambda x:x['cat']) return HttpResponse(json.dumps(result), content_type='application/json') else: - raise Http404 \ No newline at end of file + raise Http404 + +#------------------------------------------------------ +# POPOVERS +#------------------------------------------------------ +import random +from django.shortcuts import render +from django.template.loader import render_to_string +def get_popover(request): + response = {'success': True} + theme_id = request.GET.get('theme_id') + themes = {'2': ['client/popups/auto_modal.html', 'client/popups/auto_banner.html'], + '32': ['client/popups/auto_modal.html', 'client/popups/auto_banner.html', 'client/popups/cemat_modal.html', 'client/popups/cemat_banner1.html', 'client/popups/cemat_banner2.html'], + '54': ['client/popups/cemat_modal.html', 'client/popups/cemat_banner1.html', 'client/popups/cemat_banner2.html'], + '26': ['client/popups/cemat_modal.html', 'client/popups/cemat_banner1.html', 'client/popups/cemat_banner2.html'], + '22': ['client/popups/cemat_modal.html', 'client/popups/cemat_banner1.html', 'client/popups/cemat_banner2.html'], + '15': ['client/popups/cemat_modal.html', 'client/popups/cemat_banner1.html', 'client/popups/cemat_banner2.html'], + '44': ['client/popups/cemat_modal.html', 'client/popups/cemat_banner1.html', 'client/popups/cemat_banner2.html'], + '30': ['client/popups/cemat_modal.html', 'client/popups/cemat_banner1.html', 'client/popups/cemat_banner2.html']} + popovers = themes.get(theme_id) + if not popovers: + popovers = ['fail'] + response['success'] = False + + popover = random.choice(popovers) + 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 \ No newline at end of file diff --git a/templates/client/blank.html b/templates/client/blank.html index 2755ecc6..0fbead5d 100644 --- a/templates/client/blank.html +++ b/templates/client/blank.html @@ -1,6 +1,8 @@ {% load static %} {% load i18n %} +{% load template_filters %} {% get_current_language as LANGUAGE_CODE %} + {% comment %} This template include basic anf main styles and js files, block with header and footer, which same in all pages, @@ -147,7 +149,7 @@ This template include basic anf main styles and js files, {% include 'client/includes/footer.html' %} {% endblock %} -
+
{% if not user.is_authenticated %} {% include 'client/popups/login.html' %} {% include 'client/popups/register.html' %} @@ -157,6 +159,99 @@ This template include basic anf main styles and js files, {% include 'client/popups/callback.html' %} + {% if not request.COOKIES.popover_test1 %} + {% if theme_for_filter %} + + + {% if theme_for_filter.id == 2 %} + {% if False|random_social %} + {% include 'client/popups/auto_modal.html' %} + {% else %} + {% include 'client/popups/auto_banner.html' %} + {% endif %} + {% endif %} + {% 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|random5 %} + {% if r == 1 %} + {% include 'client/popups/auto_modal.html' %} + {% endif %} + + {% if r == 2 %} + {% include 'client/popups/auto_banner.html' %} + {% endif %} + {% if r == 3 %} + {% include 'client/popups/cemat_modal.html' %} + {% endif %} + {% if r == 4 %} + {% include 'client/popups/cemat_banner1.html' %} + {% endif %} + {% if r == 5 %} + {% include 'client/popups/cemat_banner2.html' %} + {% endif %} + {% endwith %} + {% endif %} + + + + + {% endif %} + {% endif %} {# if user doesnt have url- show form #} {% if not request.user.is_anonymous %} diff --git a/templates/client/popups/auto_banner.html b/templates/client/popups/auto_banner.html new file mode 100644 index 00000000..e4c3a3be --- /dev/null +++ b/templates/client/popups/auto_banner.html @@ -0,0 +1,8 @@ + diff --git a/templates/client/popups/auto_modal.html b/templates/client/popups/auto_modal.html new file mode 100644 index 00000000..43b8249b --- /dev/null +++ b/templates/client/popups/auto_modal.html @@ -0,0 +1,21 @@ + diff --git a/templates/client/popups/cemat_banner1.html b/templates/client/popups/cemat_banner1.html new file mode 100644 index 00000000..5c2c49da --- /dev/null +++ b/templates/client/popups/cemat_banner1.html @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/templates/client/popups/cemat_banner2.html b/templates/client/popups/cemat_banner2.html new file mode 100644 index 00000000..25dd1c34 --- /dev/null +++ b/templates/client/popups/cemat_banner2.html @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/templates/client/popups/cemat_modal.html b/templates/client/popups/cemat_modal.html new file mode 100644 index 00000000..e1ece4b8 --- /dev/null +++ b/templates/client/popups/cemat_modal.html @@ -0,0 +1,26 @@ +{% load static %} +{% load i18n %} + + diff --git a/templates/client/static_client/img/expo_b/cemat15.gif b/templates/client/static_client/img/expo_b/cemat15.gif new file mode 100644 index 00000000..9493a63b Binary files /dev/null and b/templates/client/static_client/img/expo_b/cemat15.gif differ diff --git a/templates/client/static_client/img/expo_b/cemat15_v2.gif b/templates/client/static_client/img/expo_b/cemat15_v2.gif new file mode 100644 index 00000000..6434be8f Binary files /dev/null and b/templates/client/static_client/img/expo_b/cemat15_v2.gif differ diff --git a/templates/client/static_client/img/expo_b/cemat_modal1.png b/templates/client/static_client/img/expo_b/cemat_modal1.png new file mode 100644 index 00000000..ec9f86b3 Binary files /dev/null and b/templates/client/static_client/img/expo_b/cemat_modal1.png differ diff --git a/templates/client/static_client/img/expo_b/cemat_modal2.png b/templates/client/static_client/img/expo_b/cemat_modal2.png new file mode 100644 index 00000000..76ded781 Binary files /dev/null and b/templates/client/static_client/img/expo_b/cemat_modal2.png differ diff --git a/templates/client/static_client/img/expo_b/mims.png b/templates/client/static_client/img/expo_b/mims.png new file mode 100644 index 00000000..b3c3929b Binary files /dev/null and b/templates/client/static_client/img/expo_b/mims.png differ diff --git a/templates/client/static_client/img/expo_b/mims15.gif b/templates/client/static_client/img/expo_b/mims15.gif new file mode 100644 index 00000000..7557051e Binary files /dev/null and b/templates/client/static_client/img/expo_b/mims15.gif differ