commit
50beeb8ded
15 changed files with 219 additions and 20 deletions
@ -1,20 +1,141 @@ |
||||
# -*- coding: utf-8 -*- |
||||
import MySQLdb |
||||
import os.path |
||||
from MySQLdb.cursors import DictCursor |
||||
from django.utils.translation import activate |
||||
from django.core.management.base import BaseCommand |
||||
from meta.models import MetaSetting |
||||
from django.conf import settings |
||||
from exposition.models import Exposition |
||||
from theme.models import Theme |
||||
from theme.models import Theme, Tag |
||||
|
||||
|
||||
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() |
||||
activate('ru') |
||||
#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_tag(expo, 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('----------------------') |
||||
""" |
||||
|
||||
|
||||
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 |
||||
|
||||
find_old = """ |
||||
SELECT products.products_id, url, products_img1 as logo |
||||
from products |
||||
LEFT JOIN `products_description` ON products.products_id=products_description.products_id |
||||
WHERE url='%s' |
||||
""" |
||||
cursor.execute(find_old%expo.old_url) |
||||
result = cursor.fetchall() |
||||
if not result: |
||||
return |
||||
logo = result[0]['logo'] |
||||
|
||||
|
||||
if logo: |
||||
logo = logo.replace('..', '') |
||||
|
||||
print(logo) |
||||
print(os.path.isfile(settings.MEDIA_ROOT[:-1]+logo)) |
||||
if (os.path.isfile(settings.MEDIA_ROOT[:-1]+logo)): |
||||
|
||||
expo.logo = logo |
||||
expo.save() |
||||
|
||||
|
||||
|
||||
@ -1,9 +1,24 @@ |
||||
{% load static %} |
||||
{% load template_filters %} |
||||
|
||||
<div class="abn"> |
||||
{% comment %} |
||||
{% if False|random3 == 1 %} |
||||
<a target="_blank" href="/redirect/redirect/31/"><img src="{% static 'client/img/partners/expomap-seminars-01.jpg' %}" alt="" /></a> |
||||
{% else %} |
||||
{% if False|random3 == 2 %} |
||||
<a target="_blank" href="/redirect/redirect/32/"><img src="{% static 'client/img/partners/expomap-seminars-02.gif' %}" alt="" /></a> |
||||
{% else %} |
||||
<a target="_blank" href="/redirect/redirect/33/"><img src="{% static 'client/img/partners/expomap-seminars-03.gif' %}" alt="" /></a> |
||||
{% endif %} |
||||
{% endif %} |
||||
{% endcomment %} |
||||
|
||||
{% comment %} |
||||
{% if False|fourth %} |
||||
<a target="_blank" href="/redirect/redirect/21/"><img src="{% static 'client/img/partners/unnamed.gif' %}" alt="" /></a> |
||||
{% else %} |
||||
<a target="_blank" href="/redirect/redirect/23/"><img src="{% static 'client/img/partners/unnamed_1.gif' %}" alt="" /></a> |
||||
{% endif %} |
||||
{% endcomment %} |
||||
</div> |
||||
@ -0,0 +1,6 @@ |
||||
<html> |
||||
<head> |
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
||||
</head> |
||||
<body>Verification: 4c326c16c916403e</body> |
||||
</html> |
||||
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 78 KiB |
Loading…
Reference in new issue