parent
e87e82c2ac
commit
a1c822d112
1 changed files with 39 additions and 11 deletions
@ -1,20 +1,48 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
|
import MySQLdb |
||||||
|
from MySQLdb.cursors import DictCursor |
||||||
from django.core.management.base import BaseCommand |
from django.core.management.base import BaseCommand |
||||||
from meta.models import MetaSetting |
from exposition.models import Exposition |
||||||
|
from theme.models import Theme |
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand): |
class Command(BaseCommand): |
||||||
def handle(self, *args, **options): |
def handle(self, *args, **options): |
||||||
a = MetaSetting.objects.filter(translations__h1__contains='«').count() |
expos = Exposition.objects.filter(theme__isnull=True, old_url__isnull=False) |
||||||
qs = MetaSetting.objects.language('ru').all() |
db = MySQLdb.connect(host="localhost", |
||||||
for item in qs: |
user="expomap", |
||||||
item.title = item.title.replace(u'«', u'').replace(u'»', u'') |
passwd="7FbLtAGjse", |
||||||
item.description = item.title.replace(u'«', u'').replace(u'»', u'') |
db="old_db", |
||||||
item.h1 = item.h1.replace(u'«', u'').replace(u'»', u'') |
charset='utf8', |
||||||
#item.save() |
cursorclass=DictCursor) |
||||||
|
cursor = db.cursor() |
||||||
|
|
||||||
|
find_old_id = """ |
||||||
|
SELECT products.products_id |
||||||
|
from products |
||||||
|
LEFT JOIN `products_description` ON products.products_id=products_description.products_id |
||||||
|
WHERE url='%s' |
||||||
|
""" |
||||||
|
|
||||||
|
find_themes = "SELECT categories_id FROM `products_to_categories` WHERE `products_id` =%d" |
||||||
|
|
||||||
|
for expo in expos: |
||||||
|
cursor.execute(find_old_id%expo.old_url) |
||||||
|
old_ids = [item['products_id'] for item in cursor.fetchall()] |
||||||
|
print expo.old_url |
||||||
|
for id in old_ids: |
||||||
|
cursor.execute(find_themes%id) |
||||||
|
themes_ids = [item['categories_id'] for item in cursor.fetchall()] |
||||||
|
print themes_ids |
||||||
|
#if not themes_ids: |
||||||
|
# continue |
||||||
|
|
||||||
|
|
||||||
|
theme_qs = Theme.objects.filter(id__in=themes_ids) |
||||||
|
#expo.theme.add(*theme_qs) |
||||||
|
break |
||||||
|
|
||||||
|
print('----------------------') |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in new issue