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

@ -1,11 +1,15 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import datetime import datetime
from logging import getLogger
from django import template from django import template
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from expobanner.models import BannerGroup, URL from expobanner.models import BannerGroup, URL
from expobanner.utils import get_banner_by_params, get_client_ip, get_referer_view from expobanner.utils import get_banner_by_params, get_client_ip, get_referer_view
log = getLogger('mail')
register = template.Library() register = template.Library()
@ -98,65 +102,68 @@ def set_var(parser, token):
@register.inclusion_tag('client/includes/banners/top_head_banner.html', takes_context=True) @register.inclusion_tag('client/includes/banners/top_head_banner.html', takes_context=True)
def get_top_banner(context): def get_top_banner(context):
# fill parameters dict # fill parameters dict
request = context.get('request') try:
request = context.get('request')
params = {'theme': context.get('themes', []),
'tag': context.get('tag', []), params = {'theme': context.get('themes', []),
'country': context.get('country', []), 'tag': context.get('tag', []),
'city': context.get('city', []), 'country': context.get('country', []),
'ip': get_client_ip(request)} 'city': context.get('city', []),
good_urls = [] 'ip': get_client_ip(request)}
urls = URL.cached.all() good_urls = []
url = get_referer_view(request, default='/') urls = URL.cached.all()
for u in urls: url = get_referer_view(request, default='/')
if u.regex: for u in urls:
try: if u.regex:
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: try:
img = banner.img.url url_re = re.compile(u.url)
except ValueError: except:
continue continue
alt = banner.alt if url_re.findall(url):
is_img = True good_urls.append(u)
result = {'id': group, elif url == u.url:
'url': banner.get_click_link(), good_urls.append(u)
'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 return result

Loading…
Cancel
Save