remotes/origin/stage6
Alexander Burdeinyi 9 years ago
parent a4d63ec04e
commit 76da82f701
  1. 119
      settings/templatetags/tempalte_tags.py

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import datetime
from logging import getLogger
import re
from django import template
from django.utils.translation import ugettext as _
@ -8,8 +8,6 @@ from django.utils.translation import ugettext as _
from expobanner.models import BannerGroup, URL
from expobanner.utils import get_banner_by_params, get_client_ip, get_referer_view
log = getLogger('mail')
register = template.Library()
@ -102,68 +100,65 @@ def set_var(parser, token):
@register.inclusion_tag('client/includes/banners/top_head_banner.html', takes_context=True)
def get_top_banner(context):
# fill parameters dict
try:
request = context.get('request')
params = {'theme': context.get('themes', []),
'tag': context.get('tag', []),
'country': context.get('country', []),
'city': context.get('city', []),
'ip': get_client_ip(request)}
good_urls = []
urls = URL.cached.all()
url = get_referer_view(request, default='/')
for u in urls:
if u.regex:
request = context.get('request')
params = {'theme': context.get('themes', []),
'tag': context.get('tag', []),
'country': context.get('country', []),
'city': context.get('city', []),
'ip': get_client_ip(request)}
good_urls = []
urls = URL.cached.all()
url = get_referer_view(request, default='/')
for u in urls:
if u.regex:
try:
url_re = re.compile(u.url)
except:
continue
if url_re.findall(url):
good_urls.append(u)
elif url == u.url:
good_urls.append(u)
group_banners = BannerGroup.cached.group_banners()
result = {}
cookie = None
places = ['top_page_banner']
for group, banners in group_banners.iteritems():
if group not in places:
continue
banner = get_banner_by_params(banners, good_urls, params, request)
# import pdb; pdb.set_trace() # on this page there is no such group
if banner:
if banner.html:
text = banner.text
img = ''
alt = ''
is_img = False
else:
text = ''
try:
url_re = re.compile(u.url)
except:
img = banner.img.url
except ValueError:
continue
if url_re.findall(url):
good_urls.append(u)
elif url == u.url:
good_urls.append(u)
alt = banner.alt
is_img = True
result = {'id': group,
'url': banner.get_click_link(),
'is_html': banner.html,
'is_flash': banner.flash,
'is_img': is_img,
'is_popup': banner.popup,
'img': img,
'alt': alt,
'text': text
}
if banner.popup:
cookie = banner.cookie
# add view log
banner.log(request, 1)
group_banners = BannerGroup.cached.group_banners()
result = {}
cookie = None
places = ['top_page_banner']
for group, banners in group_banners.iteritems():
if group not in places:
continue
banner = get_banner_by_params(banners, good_urls, params, request)
# import pdb; pdb.set_trace() # on this page there is no such group
if banner:
if banner.html:
text = banner.text
img = ''
alt = ''
is_img = False
else:
text = ''
try:
img = banner.img.url
except (ValueError, ) as e:
log.log(e)
continue
alt = banner.alt
is_img = True
result = {'id': group,
'url': banner.get_click_link(),
'is_html': banner.html,
'is_flash': banner.flash,
'is_img': is_img,
'is_popup': banner.popup,
'img': img,
'alt': alt,
'text': text
}
if banner.popup:
cookie = banner.cookie
# add view log
banner.log(request, 1)
except (Exception, ) as e:
log.log(e)
return result

Loading…
Cancel
Save