commit
f0158d8bb7
20 changed files with 372 additions and 172 deletions
@ -0,0 +1,45 @@ |
||||
# -*- coding: utf-8 -*- |
||||
import MySQLdb |
||||
from MySQLdb.cursors import DictCursor |
||||
from django.core.management.base import BaseCommand, CommandError |
||||
from functions.translate import fill_with_signal |
||||
from article.models import Article |
||||
from accounts.models import User |
||||
from django.db import IntegrityError |
||||
import xlwt |
||||
from django.utils import translation |
||||
from django.conf import settings |
||||
|
||||
class Command(BaseCommand): |
||||
def handle(self, *args, **options): |
||||
translation.activate('en') |
||||
|
||||
workbook = xlwt.Workbook(encoding = 'utf8') |
||||
worksheet = workbook.add_sheet('My Worksheet') |
||||
|
||||
font = xlwt.Font() |
||||
font.name = 'Times New Roman' |
||||
font.bold = True |
||||
|
||||
style = xlwt.XFStyle() |
||||
# Create the Style |
||||
style.font = font |
||||
|
||||
qs = Article.objects.news() |
||||
worksheet.write(0, 0, 'id') |
||||
worksheet.write(0, 1, 'url') |
||||
worksheet.write(0, 2, 'title') |
||||
|
||||
row = 1 |
||||
for a in qs: |
||||
print a.id |
||||
url = a.slug |
||||
id = a.id |
||||
name = a.main_title |
||||
|
||||
worksheet.write(row, 0, id) |
||||
worksheet.write(row, 1, url) |
||||
worksheet.write(row, 2, name) |
||||
|
||||
row += 1 |
||||
workbook.save(settings.MEDIA_ROOT+'/import/exported_news.xls') |
||||
@ -0,0 +1,22 @@ |
||||
# -*- coding: utf-8 -*- |
||||
from django.core.management.base import BaseCommand, CommandError |
||||
from city.models import City |
||||
from country.models import Country |
||||
from functions.form_check import translit_with_separator |
||||
from django.db import IntegrityError |
||||
|
||||
|
||||
class Command(BaseCommand): |
||||
def handle(self, *args, **options): |
||||
|
||||
qs = City.objects.language('en').filter() |
||||
for c in qs: |
||||
url = translit_with_separator(c.name.encode('utf8')) |
||||
c.url = url |
||||
try: |
||||
c.save() |
||||
except IntegrityError: |
||||
continue |
||||
|
||||
print(c.url) |
||||
#print(qs.count()) |
||||
@ -0,0 +1 @@ |
||||
__author__ = 'root' |
||||
@ -0,0 +1 @@ |
||||
__author__ = 'root' |
||||
@ -0,0 +1,186 @@ |
||||
# -*- coding: utf-8 -*- |
||||
import MySQLdb |
||||
import datetime |
||||
from MySQLdb.cursors import DictCursor |
||||
from django.core.management.base import BaseCommand, CommandError |
||||
from functions.translate import fill_with_signal |
||||
from translator.models import Translator |
||||
from accounts.models import User, Profile |
||||
from country.models import Country |
||||
from city.models import City |
||||
from functions.form_check import is_positive_integer |
||||
|
||||
|
||||
|
||||
def to_phone(phone): |
||||
|
||||
if not phone: |
||||
return None |
||||
|
||||
deduct = ('-','(',')','.',' ', '+') |
||||
for elem in deduct: |
||||
phone = phone.replace(elem, '') |
||||
if phone.isdigit(): |
||||
return int(phone) |
||||
else: |
||||
return None |
||||
|
||||
|
||||
def get_country_name(id): |
||||
db = MySQLdb.connect(host="localhost", |
||||
user="kotzilla", |
||||
passwd="qazedc", |
||||
db="crm", |
||||
charset='utf8', |
||||
cursorclass=DictCursor) |
||||
sql =""" |
||||
SELECT country_name as name |
||||
FROM `country` |
||||
WHERE `country_id` =%d"""%id |
||||
|
||||
cursor = db.cursor() |
||||
cursor.execute(sql) |
||||
result = cursor.fetchone() |
||||
return result['name'] |
||||
|
||||
|
||||
def get_city_name(id): |
||||
db = MySQLdb.connect(host="localhost", |
||||
user="kotzilla", |
||||
passwd="qazedc", |
||||
db="crm", |
||||
charset='utf8', |
||||
cursorclass=DictCursor) |
||||
sql =""" |
||||
SELECT city_name as name |
||||
FROM `city` |
||||
WHERE `city_id` =%d"""%id |
||||
cursor = db.cursor() |
||||
cursor.execute(sql) |
||||
result = cursor.fetchone() |
||||
return result['name'] |
||||
|
||||
class Command(BaseCommand): |
||||
def handle(self, *args, **options): |
||||
db = MySQLdb.connect(host="localhost", |
||||
user="kotzilla", |
||||
passwd="qazedc", |
||||
db="crm", |
||||
charset='utf8', |
||||
cursorclass=DictCursor) |
||||
cursor = db.cursor() |
||||
sql = """SELECT * |
||||
FROM `interpreter_table` """ |
||||
|
||||
cursor.execute(sql) |
||||
result = cursor.fetchall() |
||||
|
||||
|
||||
|
||||
for data in result: |
||||
email = data['email'] |
||||
print(email.encode('utf8')) |
||||
|
||||
if email: |
||||
try: |
||||
user = User.objects.select_related('translator').get(username=email) |
||||
|
||||
except User.DoesNotExist: |
||||
user = None |
||||
if user: |
||||
# add information to user |
||||
profile = user.profile |
||||
if data['phone1']: |
||||
phone = to_phone(data['phone1']) |
||||
if len(str(phone))<15: |
||||
profile.phone = phone |
||||
if data['skype']: |
||||
|
||||
profile.skype = data['skype'] |
||||
if data['country_id']: |
||||
name = get_country_name(data['country_id']) |
||||
country_qs = Country.objects.filter(translations__name=name) |
||||
if country_qs.exists(): |
||||
country = country_qs[0] |
||||
else: |
||||
country = None |
||||
profile.country = country |
||||
|
||||
if profile.country and data['city_id']: |
||||
name = get_city_name(data['city_id']) |
||||
city_qs = City.objects.filter(translations__name=name, country=profile.country) |
||||
if city_qs.exists(): |
||||
city = city_qs[0] |
||||
else: |
||||
city = None |
||||
profile.city = city |
||||
|
||||
profile.save() |
||||
|
||||
|
||||
else: |
||||
# create new user |
||||
user = User.objects.create_user(email, data['fam'], data['name'], data['pass']) |
||||
user.is_active = True |
||||
user.save() |
||||
profile = user.profile |
||||
#user.url = 'id%s'%str(self.id) |
||||
if data['phone1']: |
||||
phone = to_phone(data['phone1']) |
||||
if len(str(phone))<15: |
||||
profile.phone = phone |
||||
if data['skype']: |
||||
profile.skype = data['skype'] |
||||
if data['country_id']: |
||||
name = get_country_name(data['country_id']) |
||||
country_qs = Country.objects.filter(translations__name=name) |
||||
if country_qs.exists(): |
||||
country = country_qs[0] |
||||
else: |
||||
country = None |
||||
profile.country = country |
||||
|
||||
if profile.country and data['city_id']: |
||||
name = get_city_name(data['city_id']) |
||||
city_qs = City.objects.filter(translations__name=name, country=profile.country) |
||||
if city_qs.exists(): |
||||
city = city_qs[0] |
||||
else: |
||||
city = None |
||||
profile.city = city |
||||
|
||||
profile.save() |
||||
|
||||
user.save() |
||||
|
||||
# fill translator |
||||
if user.translator: |
||||
translator_id = user.translator_id |
||||
translator = Translator.objects.language('ru').get(id=translator_id) |
||||
new = 0 |
||||
else: |
||||
translator = Translator() |
||||
new = 1 |
||||
|
||||
gender = data['gender'] |
||||
if gender == u'мужской': |
||||
gender = 'male' |
||||
elif gender == u'женский': |
||||
gender = 'female' |
||||
else: |
||||
gender = 'male' |
||||
translator.gender = gender |
||||
|
||||
translator.birth = data['born'] |
||||
if data['automobile'] == u'да': |
||||
translator.car = 1 |
||||
if new: |
||||
translator.translate('ru') |
||||
|
||||
translator.education = data['education'] |
||||
translator.specialization = data['spec'] |
||||
translator.languages = ', '.join([data['selfLang'], data['selfLang2']]) |
||||
translator.save() |
||||
user.translator = translator |
||||
|
||||
user.save() |
||||
Loading…
Reference in new issue