# -*- coding: utf-8 -*- # bad practice of importing, but to many functions must be imported from .utils import * def get_bool(value): if value: return 1 return '' def get_int(value): if not value: return '' return value def get_theme(value): objects = value.theme.all() return ','.join(str(obj.id) for obj in objects) def get_tag(tag, theme): tags = tag.all() themes = theme.all() result = '' for theme in themes: # list of tags with current theme tag_list = [str(tag.id) for tag in tags if tag.theme == theme] result += '['+','.join(tag_list)+']' return result def get_place_type(value): for t in EXPOSITION_TYPE: if value == t[0]: return t[1] return t[0][1] place_settings=[ {'name': 'id', 'verbose_name': u'id', 'type': get_int, 'width':1500}, {'name': 'name', 'verbose_name': u'Название', 'type': unicode}, {'name': 'type', 'verbose_name': u'Тип', 'type': get_place_type},########## {'name': 'main_title', 'verbose_name': u'Краткое описание', 'type': unicode}, {'name': 'country', 'verbose_name': u'Страна', 'type': unicode}, {'name': 'city', 'verbose_name': u'Город', 'type': unicode}, {'name': 'address', 'verbose_name': u'Адресс', 'type': unicode}, {'name': 'phone', 'verbose_name': u'Тел.', 'type': get_int}, {'name': 'fax', 'verbose_name': u'Факс', 'type': get_int}, {'name': 'web_page', 'verbose_name': u'Веб-сайт', 'type': unicode}, {'name': 'email', 'verbose_name': u'Email', 'type': unicode}, {'name': 'virtual_tour', 'verbose_name': u'Виртуальный тур', 'type': unicode}, {'name': 'virtual_tour', 'verbose_name': u'Виртуальный тур', 'type': unicode}, {'name': 'foundation_year', 'verbose_name': u'Год основания', 'type': get_int}, {'name': 'event_in_year', 'verbose_name': u'Количество мероприятий в год', 'type': get_int}, {'name': 'total_area', 'verbose_name': u'Общая выставочная площадь, кв. м.', 'type': get_int}, {'name': 'closed_area', 'verbose_name': u'Закрытая выставочная площадь, кв. м.', 'type': get_int}, {'name': 'open_area', 'verbose_name': u'Открытая выставочная площадь, кв. м.', 'type': get_int}, {'name': 'total_pavilions', 'verbose_name': u'Количество павильонов', 'type': get_int}, {'name': 'total_halls', 'verbose_name': u'Конференц-залы', 'type': get_int}, {'name': 'bank', 'verbose_name': u'Банк/Банкоматы/Обмен валюты', 'type': get_bool}, {'name': 'children_room', 'verbose_name': u'Детская комната', 'type': get_bool}, {'name': 'disabled_service', 'verbose_name': u'Сервис для людей с ограниченными физическими возможностями', 'type': get_bool}, {'name': 'conference_centre', 'verbose_name': u'Конгресс-центр', 'type': get_bool}, {'name': 'business_centre', 'verbose_name': u'Бизнес-центр', 'type': get_bool}, {'name': 'online_registration', 'verbose_name': u'On-line регистрация', 'type': get_bool}, {'name': 'wifi', 'verbose_name': u'Wi-Fi', 'type': get_bool}, {'name': 'cafe', 'verbose_name': u'Кафе и рестораны', 'type': get_bool}, {'name': 'terminals', 'verbose_name': u'Информационные терминалы', 'type': get_bool}, {'name': 'parking', 'verbose_name': u'Парковка', 'type': get_bool}, {'name': 'press_centre', 'verbose_name': u'Пресс-центр', 'type': get_bool}, {'name': 'mobile_application', 'verbose_name': u'Мобильное приложение', 'type': get_bool}, ] field_settings = [ {'name': 'id', 'verbose_name': u'id', 'type': get_int, 'width':1500}, {'name': 'url', 'verbose_name': u'url', 'type': unicode}, {'name': 'name', 'verbose_name': u'Название', 'type': unicode}, #{'name': 'type', 'verbose_name': u'Тип', 'type': get_place_type, 'width':8000}, {'name': 'data_begin', 'verbose_name': u'Дата начала', 'type': unicode}, {'name': 'data_end', 'verbose_name': u'Дата окончания', 'type': unicode}, {'name': 'audience', 'verbose_name': u'Аудитория', 'type': get_audience}, {'name': 'main_title', 'verbose_name': u'Краткое описание', 'type': unicode}, {'name': 'description', 'verbose_name': u'Описание', 'type': unicode}, {'name': 'country', 'verbose_name': u'Страна', 'type': unicode}, {'name': 'city', 'verbose_name': u'Город', 'type': unicode}, # {'name': 'theme', 'verbose_name': u'Тематика', 'type': get_theme, 'width':8000}, {'name': 'tag', 'verbose_name': u'Теги', 'type': get_tag, 'width':8000}, {'name': 'address', 'verbose_name': u'Адрес', 'type': unicode}, #{'name': 'periodic', 'verbose_name': 'Периодичность', 'type': str}, {'name': 'web_page', 'verbose_name': u'Веб страница', 'type': unicode}, {'name': 'email', 'verbose_name': u'Email', 'type': unicode}, {'name': 'phone', 'verbose_name': u'Телефон', 'type': get_int}, {'name': 'time', 'verbose_name': u'Время проведения', 'type': unicode}, {'name': 'products', 'verbose_name': u'Экспонируемые продукты', 'type': unicode}, {'name': 'foundation', 'verbose_name': u'Год основания', 'type': get_int}, #{'name': 'events_number', 'verbose_name': u'Год основания', 'type': get_int}, {'name': 'staff_number', 'verbose_name': u'Год основания', 'type': get_int}, {'name': 'specialization', 'verbose_name': u'Год основания', 'type': unicode}, {'name': 'foundation_year', 'verbose_name': u'Год основания', 'type': get_int}, {'name': 'tax', 'verbose_name': u'Налог включен', 'type': get_bool, 'width':1000}, {'name': 'currency', 'verbose_name': u'Валюта', 'type': unicode}, {'name': 'max_price', 'verbose_name': u'Максимальная цена', 'type': get_int}, {'name': 'min_price', 'verbose_name': u'Минимальная цена', 'type': get_int}, {'name': 'registration_payment', 'verbose_name': u'Регистрационный взнос', 'type': get_int}, {'name': 'min_closed_area', 'verbose_name': u'Минимальная цена закрытой НЕ оборудованной площади', 'type': get_int}, {'name': 'max_closed_area', 'verbose_name': u'Максимальная цена закрытой НЕ оборудованной площади', 'type': get_int}, {'name': 'min_closed_equipped_area', 'verbose_name': u'Минимальная цена закрытой оборудованной площади ', 'type': get_int}, {'name': 'max_closed_equipped_area', 'verbose_name': u'Максимальная цена закрытой оборудованной площади', 'type': get_int}, {'name': 'min_open_area', 'verbose_name': u'Минимальная цена закрытой площади', 'type': get_int}, {'name': 'max_open_area', 'verbose_name': u'Максимальная цена открытой площади', 'type': get_int}, {'name': 'min_area', 'verbose_name': u'Минимальная площадь', 'type': get_int}, {'name': 'max_area', 'verbose_name': u'Максимальная площадь', 'type': get_int}, {'name': 'is_published', 'verbose_name': u'Опубликована', 'type': get_bool}, {'name': 'canceled_by_administrator', 'verbose_name': u'Отменена администратором', 'type': get_bool} ] def to_theme_type(st): if not st: return 15 types = st.split(',') flag = 0 flag = reduce(lambda x,y: x|y, (getattr(Theme.types, item) for item in types)) return flag def to_currency(value): if value=='USD': return value if value=='EUR': return value print(value) return 'USD' def to_logo(url): return None def to_photo(url): return None def to_map(url): return None from django.core.validators import validate_email, URLValidator def to_url(url): validate = URLValidator() try: validate(url) except: return '' return url def to_email(email): try: validate_email(email) except: return '' return email from file.models import FileModel import urllib2 from django.conf import settings from django.contrib.contenttypes.models import ContentType from functions.files import get_alternative_filename def save_file(obj, value, purpose): if not obj.id: return None urls = value.split(';') for url in urls: file_name = url.split('/')[-1] alt_name = get_alternative_filename(settings.MEDIA_ROOT+'imgs/', file_name) download_to = settings.MEDIA_ROOT+'imgs/'+alt_name try: response = urllib2.urlopen(url, timeout=3) except: continue with open(download_to,'wb') as f: f.write(response.read()) f.close() file_name ='imgs/'+alt_name content_type = ContentType.objects.get_for_model(obj) file = FileModel(file_path=file_name, file_type='JPG', purpose=purpose, content_type=content_type, object_id=obj.id) file.save() from file.models import Photo def save_photo(obj, value): if not obj.id: return None urls = value.split(';') for url in urls: file_name = url.split('/')[-1] alt_name = get_alternative_filename(settings.MEDIA_ROOT+'imgs/', file_name) download_to = settings.MEDIA_ROOT+'photos/'+alt_name try: response = urllib2.urlopen(url, timeout=3) except: continue with open(download_to,'wb') as f: f.write(response.read()) f.close() file_name ='photos/'+alt_name content_type = ContentType.objects.get_for_model(obj) photo = Photo(file_path=file_name, file_type='JPG', content_type=content_type, object_id=obj.id) photo.save() from place_exposition.models import EXPOSITION_TYPE def to_type(value): for t in EXPOSITION_TYPE: if value == t[1]: return t[0] return 'Exposition complex' def to_phone(value): if value: if isinstance(value, float) or isinstance(value, int): return value else: deduct = ('-','(',')','.',' ', '+') for elem in deduct: value = value.replace(elem, '') value = to_int(value) return value from place_exposition.models import Hall def save_halls(obj, value): halls = value.split(';') res = [] for hall in halls: if hall: area = None number = None name = '' l = hall.split(u'-') if len(l)>1: area = int(l[1].strip().replace(' ', '')) l = l[0].split(u'№') if len(l)>1: try: number = int(l[1].strip()) except ValueError: pass name = l[0].strip() else: name = l[0].strip() else: name = l[0].strip() res.append({'area': area, 'name':name, 'number': number}) Hall.objects.filter(place_exposition=obj).delete() for hall in res: h = Hall(place_exposition = obj, name=hall.get('name'), number=hall.get('number'), capacity=hall.get('area')) try: h.save() except Exception, e: print('---------------hall error---------') print e print('---------------------------------') place_exp_sett = { u'ID':{u'field': u'id', u'func': to_int}, u'Название ВЦ':{u'field': u'name', u'func': unicode}, u'Тип':{u'field': u'type', u'func': to_type}, u'Краткое описание':{u'field': u'main_title', u'func': unicode}, u'Страна':{u'field': u'country', u'func': to_country}, u'Город':{u'field': u'city', u'func': to_city, 'extra_values': 'country'}, u'Описание':{u'field': u'description', u'func': unicode}, u'Адрес':{u'field': u'adress', u'func': unicode}, u'Тел.':{u'field': u'phone', u'func': to_phone}, u'Факс':{u'field': u'fax', u'func': to_phone}, u'Фото':{u'field': u'photo', u'func': save_photo, u'method': True}, u'Лого':{u'field': u'logo', u'func': save_logo, u'method': True}, u'Веб-сайт':{u'field': u'web_page', u'func': unicode}, u'Email':{u'field': u'email', u'func': unicode}, u'Карта проезда':{u'field': u'map', u'func': save_file, u'method': True, u'purpose': 'map'}, u'Виртуальный тур':{u'field': u'virtual_tour', u'func': to_url}, u'Год основания':{u'field': u'foundation_year', u'func': to_int}, u'Валюта':{u'field': u'currency', u'func': to_currency}, u'Количество мероприятий в год':{u'field': u'event_in_year', u'func': to_int}, u'Общая выставочная площадь, кв. м.':{u'field': u'total_area', u'func': to_int}, u'Закрытая выставочная площадь, кв. м.':{u'field': u'closed_area', u'func': to_int}, u'Открытая выставочная площадь, кв. м.':{u'field': u'open_area', u'func': to_int}, u'Количество павильонов':{u'field': u'total_pavilions', u'func': to_int}, u'Площадь павильона':{u'field': u'halls', u'func': save_halls, u'method': True}, u'Конференц-залы':{u'field': u'total_halls', u'func': to_int}, u'Схема территории':{u'field': u'scheme', u'func': save_file, u'method': True, u'purpose': 'scheme teritory'},#сделать u'Банк/Банкоматы/Обмен валюты':{u'field': u'bank', u'func': bool}, u'Детская комната':{u'field': u'children_room', u'func': bool}, u'Сервис для людей с ограниченными физическими возможностями':{u'field': u'disabled_service', u'func': bool}, u'Конгресс-центр':{u'field': u'conference_centre', u'func': bool}, u'Бизнес-центр':{u'field': u'business_centre', u'func': bool}, u'On-line регистрация':{u'field': u'online_registration', u'func': bool}, u'Wi-Fi':{u'field': u'wifi', u'func': bool}, u'Кафе и рестораны':{u'field': u'cafe', u'func': bool}, u'Информационные терминалы':{u'field': u'terminals', u'func': bool}, u'Парковка':{u'field': u'parking', u'func': bool}, u'Пресс-центр':{u'field': u'press_centre', u'func': bool}, u'Мобильное приложение':{u'field': u'mobile_application', u'func': bool}, } event_sett = { u'ID':{u'field': u'id', u'func': to_int}, u'Url':{u'field': u'url', u'func': unicode}, u'Название':{u'field': u'name', u'func': unicode}, u'Краткое описание':{u'field': u'main_title', u'func': unicode}, u'Дата начала:(YYYY-MM-DD)':{u'field': u'data_begin', u'func': to_date}, u'Дата окончания:(YYYY-MM-DD)':{u'field': u'data_end', u'func': to_date}, u'Страна':{u'field': u'country', u'func': to_country}, u'Город':{u'field': u'city_id', u'func': to_city, 'extra_values': 'country'}, u'Место проведения':{u'field': u'place', u'func': to_place}, u'ID Тематики':{u'field': u'theme', u'func': to_theme, u'method': True},### u'Теги':{u'field': u'tag', u'func': to_tag, u'method': True}, #u'Организатор №1':{u'field': u'organiser', u'func': to_tag},#### #u'Организатор №2':{u'field': u'organiser', u'func': to_tag},#### u'Описание события':{u'field': u'description', u'func': unicode}, u'Периодичность':{u'field': u'periodic', u'func': to_periodic},### u'Аудитория':{u'field': u'audience', u'func': to_audience}, u'Официальный веб-сайт':{u'field': u'web_page', u'func': to_url}, u'Экспонируемые продукты':{u'field': u'products', u'func': unicode}, u'Время работы':{u'field': u'time', u'func': unicode}, u'Логотип':{u'field': u'logo', u'func': save_logo, u'method': True}, u'Валюта':{u'field': u'currency', u'func': unicode}, u'Стоимость билета 1 день':{u'field': u'price_day', u'func': unicode}, u'Стоимость билета все дни':{u'field': u'price_all', u'func': unicode}, u'Условия предварительной регистрации':{u'field': u'pre_condition', u'func': unicode}, u'Стоимость на стойке 1 день':{u'field': u'price_day_bar', u'func': unicode}, u'Стоимость на стойке все дни':{u'field': u'price_all_bar', u'func': unicode}, u'Условия регистрации на стойке':{u'field': u'stand_condition', u'func': unicode}, u'Примечание по посещению':{u'field': u'visit_note', u'func': unicode}, u'Каталог':{u'field': u'price_catalog', u'func': to_int}, u'Налог включен':{u'field': u'tax', u'func': bool}, u'Год основания':{u'field': u'foundation_year', u'func': to_int}, #???u'Данные за год':{u'field': u'periodic', u'func': to_int}, u'Посетители':{u'field': u'visitors', u'func': to_int}, u'Участники':{u'field': u'members', u'func': to_int}, u'Страны':{u'field': u'stat_countries', u'func': unicode}, u'Площадь':{u'field': u'area', u'func': to_int}, u'Min_Raw кв.м.':{u'field': u'min_closed_area', u'func': to_int}, u'Max_Raw кв.м.':{u'field': u'max_closed_area', u'func': to_int}, u'Min_Pack кв.м.':{u'field': u'min_closed_equipped_area', u'func': to_int}, u'Max_Pack кв.м.':{u'field': u'max_closed_equipped_area', u'func': to_int}, u'Открытая площадь':{u'field': u'max_open_area', u'func': to_int}, u'Мин. Площадь кв.м.':{u'field': u'min_stand_size', u'func': to_int}, u'Регистрационный взнос':{u'field': u'registration_payment', u'func': to_int}, u'Примечание по участии':{u'field': u'participation_note', u'func': unicode}, u'Крайний срок подачи заявки':{u'field': u'application_deadline', u'func': to_date}, u'UFI':{u'field': u'quality_label', u'func': check_quality_label, u'bitfield':True, u'label': 'ufi'}, u'РСВЯ':{u'field': u'quality_label', u'func': check_quality_label, u'bitfield':True, u'label': 'rsva'}, u'EXPORATING':{u'field': u'quality_label', u'func': check_quality_label, u'bitfield':True, u'label': 'exporating'}, u'Отменена':{u'field': u'canceled', u'func': bool}, u'ExpoHIT':{u'field': u'expohit', u'func': bool}, } import_settings={ 'name': {'func': unicode}, 'url': {'func': unicode}, 'data_begin': {'func': to_date}, 'data_end': {'func': to_date}, 'main_title': {'func': unicode}, 'description': {'func': unicode}, 'audience': {'func': to_audience}, 'country': {'func': to_country}, 'city': {'func': to_city, 'extra_values': 'country'}, 'theme': {'func': to_theme}, 'tag': {'func': to_tag, 'extra_values': 'theme'}, 'periodic': {'func': unicode}, 'web_page': {'func': unicode}, 'time': {'func': unicode}, 'products': {'func': unicode}, 'foundation_year': {'func': to_int}, 'tax': {'func': bool}, 'currency': {'func': unicode}, 'max_price': {'func': to_int}, 'min_price': {'func': to_int}, 'registration_payment': {'func': to_int}, 'min_closed_area': {'func': to_int}, 'max_closed_area': {'func': to_int}, 'min_closed_equipped_area': {'func': to_int}, 'max_closed)equipped_area': {'func': to_int}, 'min_open_area': {'func': to_int}, 'max_open_area': {'func': to_int}, 'min_area': {'func': to_int}, 'max_area': {'func': to_int}, 'is_published': {'func': bool}, 'canceled_by_administrator': {'func': bool}, 'types': {'func': to_theme_type} }