parent
e87e82c2ac
commit
a1c822d112
1 changed files with 39 additions and 11 deletions
@ -1,20 +1,48 @@ |
||||
# -*- coding: utf-8 -*- |
||||
import MySQLdb |
||||
from MySQLdb.cursors import DictCursor |
||||
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): |
||||
def handle(self, *args, **options): |
||||
a = MetaSetting.objects.filter(translations__h1__contains='«').count() |
||||
qs = MetaSetting.objects.language('ru').all() |
||||
for item in qs: |
||||
item.title = item.title.replace(u'«', u'').replace(u'»', u'') |
||||
item.description = item.title.replace(u'«', u'').replace(u'»', u'') |
||||
item.h1 = item.h1.replace(u'«', u'').replace(u'»', u'') |
||||
#item.save() |
||||
|
||||
|
||||
|
||||
expos = Exposition.objects.filter(theme__isnull=True, old_url__isnull=False) |
||||
db = MySQLdb.connect(host="localhost", |
||||
user="expomap", |
||||
passwd="7FbLtAGjse", |
||||
db="old_db", |
||||
charset='utf8', |
||||
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