示例#1
0
def make_translit():
    cities = City.objects.all()
    for city in cities:
        name = translit(city.name, "ru")
        try:
            name = name[0].upper() + name[1:]
        except:
            print name
        city.translit_rus = name
        city.save()
示例#2
0
def make_company_url():
    for comp in Company.objects.all():
        try:

            name = translit(comp.name.replace(" ", "_"), reversed=True)
            name = name[0].upper() + name[1:]
        except:
            name = comp.name.replace(" ", "_")
        comp.translit_eng = name.lower()
        comp.save()
示例#3
0
def save_cities(array_of_cities):

    # Удаление городов, компаний и имейлов
    City.objects.all().delete()
    Company.objects.all().delete()
    Email.objects.all().delete()

    # Сохранение новых городов
    for city in array_of_cities:
        name = city[1]
        t_name = translit(city[1], 'ru')
        t_name = t_name[0].upper() + t_name[1:]
        City.objects.create(name=name, tag=city[0], translit_rus=t_name)
示例#4
0
def create_companies(emails, title, address, phone, hours, url, c_name):

    # Создание компании
    email_models = []
    for email in emails:
        email_models.append(Email.objects.create(email=email))
    if email_models == []:
        email_models = ''

    city = City.objects.get(name=c_name)

    try:
        new_company = Company.objects.create(name=title, translit_rus=translit(title,'ru'),
                                             address=address, phone=phone,
                                             office_hours=hours, url=url, city=city,
                                             hashcode=random_string(32))
        new_company.email = email_models
        new_company.save()
    except:
        print 'exception in: {0} , {1}'.format(title, phone)