From 03f7d54e1ce10652099654d69a777bc8c253bb21 Mon Sep 17 00:00:00 2001 From: Kotiuk Nazarii Date: Tue, 30 Jun 2015 16:07:16 +0300 Subject: [PATCH] remove banners --- exposition/management/commands/test.py | 58 +++++++++++++++++-- .../client/includes/banners/under_search.html | 2 + templates/client/index.html | 2 + 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/exposition/management/commands/test.py b/exposition/management/commands/test.py index 757eb94b..022c3e6d 100644 --- a/exposition/management/commands/test.py +++ b/exposition/management/commands/test.py @@ -7,6 +7,7 @@ from django.core.management.base import BaseCommand from django.conf import settings from exposition.models import Exposition from theme.models import Theme +from theme.models import Theme, Tag class Command(BaseCommand): @@ -20,12 +21,14 @@ class Command(BaseCommand): cursorclass=DictCursor) cursor = db.cursor() activate('ru') - expos = Exposition.enable.upcoming().filter(logo='') - #expo = Exposition.objects.get(old_url='mir-detstva-i-shkoly-2015') - #handle_expo(expo, cursor) + #expos = Exposition.enable.upcoming().filter(logo='') + expos = Exposition.objects.filter(tag__isnull=True).order_by('-data_end') + #expo = Exposition.objects.get(old_url='salon-du-livre-2015') + + #handle_expo_tag(expo, cursor) for expo in expos: - handle_expo(expo, cursor) + handle_expo_tag(expo, cursor) @@ -61,7 +64,54 @@ class Command(BaseCommand): print('----------------------') """ + +def handle_expo_tag(expo, cursor): + old_url = expo.old_url + if not old_url: + return None + print(old_url) + find_old = """ + SELECT products.products_id, url + from products + LEFT JOIN `products_description` ON products.products_id=products_description.products_id + WHERE url='%s' + """ + cursor.execute(find_old%old_url) + result = cursor.fetchone() + expo_id = result.get('products_id') + if not expo_id: + return + + find_tag_id = """ + SELECT tag_id + FROM `products_tags` + WHERE `product_id` =%d + """ + cursor.execute(find_tag_id%expo_id) + tags_ids = [str(item['tag_id']) for item in cursor.fetchall()] + if not tags_ids: + return None + find_tag = """ + SELECT title + FROM `tags` + WHERE id in(%s) + """ + cursor.execute(find_tag%', '.join(tags_ids)) + tag_names = [item['title'] for item in cursor.fetchall()] + if not tag_names: + return None + + themes = [item['id'] for item in expo.theme.all().values('id')] + qs = Tag.objects.filter(translations__name__in=tag_names, theme__in=themes) + expo.tag.add(*qs) + + + def handle_expo(expo, cursor): + """ + fixing logos + + """ if expo.logo: return diff --git a/templates/client/includes/banners/under_search.html b/templates/client/includes/banners/under_search.html index 66f5e45c..ea2f6dbb 100644 --- a/templates/client/includes/banners/under_search.html +++ b/templates/client/includes/banners/under_search.html @@ -2,6 +2,7 @@ {% load template_filters %}
+ {% comment %} {% if False|random3 == 1 %} {% else %} @@ -11,6 +12,7 @@ {% endif %} {% endif %} + {% endcomment %} {% comment %} {% if False|fourth %} diff --git a/templates/client/index.html b/templates/client/index.html index b01123ab..f92e5fcd 100644 --- a/templates/client/index.html +++ b/templates/client/index.html @@ -58,6 +58,7 @@
{% block menu_banner %} + {% comment %} {% if False|random3 == 1 %} {% else %} @@ -67,6 +68,7 @@ {% endif %} {% endif %} + {% endcomment %} {% endblock %}