|
|
|
|
@ -57,7 +57,19 @@ def set_cookie(response, key, value, days_expire = 7): |
|
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_banner_by_params(banners_list, urls, params, request): |
|
|
|
|
def random_choice_banners(banners): |
|
|
|
|
''' |
|
|
|
|
Include weight of customers model. |
|
|
|
|
''' |
|
|
|
|
choice_from = {} |
|
|
|
|
for i, banner in enumerate(banners): |
|
|
|
|
key = 'customer{pk}'.format(pk=banner.customer_id) if banner.customer_id else i |
|
|
|
|
choice_from.setdefault(key, []).append(banner) |
|
|
|
|
pre_choiced = random.choice(choice_from.values()) |
|
|
|
|
return random.choice(pre_choiced) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_banner_by_params(banners_list, urls, params, request, choicer=random_choice_banners): |
|
|
|
|
thematic_banners = [] |
|
|
|
|
url_banners = [] |
|
|
|
|
|
|
|
|
|
@ -94,13 +106,13 @@ def get_banner_by_params(banners_list, urls, params, request): |
|
|
|
|
# check by url |
|
|
|
|
if urls: |
|
|
|
|
banner_urls = banner.urls.all() |
|
|
|
|
print('number of queries = %d'%len(connection.queries)) |
|
|
|
|
# print('number of queries = %d'%len(connection.queries)) |
|
|
|
|
|
|
|
|
|
if banner_urls: |
|
|
|
|
|
|
|
|
|
banner_urls = set(banner_urls) |
|
|
|
|
common_urls = set(urls).intersection(banner_urls) |
|
|
|
|
print(banner, common_urls, banner_urls, urls) |
|
|
|
|
# print(banner, common_urls, banner_urls, urls) |
|
|
|
|
if common_urls: |
|
|
|
|
url_banners.append(banner) |
|
|
|
|
continue |
|
|
|
|
@ -114,23 +126,11 @@ def get_banner_by_params(banners_list, urls, params, request): |
|
|
|
|
if result: |
|
|
|
|
sort_result = get_by_sort(result) |
|
|
|
|
# return random.choice(sort_result) |
|
|
|
|
return random_choice_banners(sort_result) |
|
|
|
|
return choicer(sort_result) |
|
|
|
|
else: |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def random_choice_banners(banners): |
|
|
|
|
''' |
|
|
|
|
Include weight of customers model. |
|
|
|
|
''' |
|
|
|
|
choice_from = {} |
|
|
|
|
for i, banner in enumerate(banners): |
|
|
|
|
key = 'customer{pk}'.format(pk=banner.customer_id) if banner.customer_id else i |
|
|
|
|
choice_from.setdefault(key, []).append(banner) |
|
|
|
|
pre_choiced = random.choice(choice_from.values()) |
|
|
|
|
return random.choice(pre_choiced) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_top_events(tops, params, request): |
|
|
|
|
catalog = params.get('catalog') |
|
|
|
|
country = params.get('country', '') |
|
|
|
|
|