|
|
|
|
@ -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 |
|
|
|
|
|
|
|
|
|
|