|
|
|
|
@ -1,7 +1,9 @@ |
|
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
from django.core.management.base import BaseCommand, CommandError |
|
|
|
|
from organiser.models import Organiser |
|
|
|
|
from theme.models import Theme, Tag |
|
|
|
|
from functions.form_check import translit_with_separator |
|
|
|
|
from accounts.models import User |
|
|
|
|
|
|
|
|
|
import MySQLdb |
|
|
|
|
from MySQLdb.cursors import DictCursor |
|
|
|
|
@ -21,9 +23,9 @@ def convert_to_int(st): |
|
|
|
|
class Command(BaseCommand): |
|
|
|
|
def handle(self, *args, **options): |
|
|
|
|
db = MySQLdb.connect(host="localhost", |
|
|
|
|
user="root", |
|
|
|
|
user="kotzilla", |
|
|
|
|
passwd="qazedc", |
|
|
|
|
db="expomap_ru", |
|
|
|
|
db="old_expomap", |
|
|
|
|
charset='utf8', |
|
|
|
|
cursorclass=DictCursor) |
|
|
|
|
|
|
|
|
|
@ -31,18 +33,18 @@ class Command(BaseCommand): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sql = """SELECT DISTINCT(customers_company) as name, specialize, otrasly as theme, tags, adress, |
|
|
|
|
phone, fax, email, website, twitter, about, customers_company.url |
|
|
|
|
sql = """SELECT DISTINCT(customers_company) as name, customers_email_address as user_email, specialize, otrasly as theme, tags, adress, |
|
|
|
|
phone, fax, email, website, twitter, about, customers_company.url, company_last_modified as modified |
|
|
|
|
FROM customers |
|
|
|
|
LEFT JOIN customers_company |
|
|
|
|
ON customers.customers_company=customers_company.title |
|
|
|
|
ON customers.customers_id = customers_company.customers_id |
|
|
|
|
WHERE customers_status = 4 |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
cursor.execute(sql) |
|
|
|
|
|
|
|
|
|
res = cursor.fetchall() |
|
|
|
|
|
|
|
|
|
print(res[0].get('user_email')) |
|
|
|
|
|
|
|
|
|
for o in res: |
|
|
|
|
if not o.get('name'): |
|
|
|
|
@ -66,7 +68,7 @@ class Command(BaseCommand): |
|
|
|
|
organiser.description = o.get('about') |
|
|
|
|
|
|
|
|
|
if organiser.name: |
|
|
|
|
print('not_saved: %s'%o['name']) |
|
|
|
|
print('not_saved: %s'%o['name'].encode('utf8')) |
|
|
|
|
organiser.save() |
|
|
|
|
print('saved: %s'%str(organiser)) |
|
|
|
|
|
|
|
|
|
@ -75,12 +77,10 @@ class Command(BaseCommand): |
|
|
|
|
if theme_id: |
|
|
|
|
try: |
|
|
|
|
theme = Theme.objects.get(id=theme_id) |
|
|
|
|
organiser.theme.add(theme) |
|
|
|
|
except Theme.DoesNotExist: |
|
|
|
|
continue |
|
|
|
|
organiser.theme.add(theme) |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
if not theme: |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
tags = o.get('tags') |
|
|
|
|
if tags: |
|
|
|
|
@ -104,5 +104,14 @@ class Command(BaseCommand): |
|
|
|
|
organiser.save() |
|
|
|
|
print(organiser) |
|
|
|
|
|
|
|
|
|
user_email = o.get('user_email') |
|
|
|
|
if user_email: |
|
|
|
|
try: |
|
|
|
|
user = User.objects.get(username=user_email) |
|
|
|
|
user.organiser = organiser |
|
|
|
|
user.save() |
|
|
|
|
except User.DoesNotExist: |
|
|
|
|
print('no user with this email: %s'%user_email) |
|
|
|
|
|
|
|
|
|
print('success') |
|
|
|
|
|
|
|
|
|
|