diff --git a/exposition/management/commands/exposition_load.py b/exposition/management/commands/exposition_load.py index 1c1895a8..d96cd9db 100644 --- a/exposition/management/commands/exposition_load.py +++ b/exposition/management/commands/exposition_load.py @@ -4,10 +4,281 @@ from city.models import City from country.models import Country from exposition.models import Exposition import xlrd, xlwt -from import_xls.excel_settings import event_sett +#from import_xls.excel_settings import event_sett from django.conf import settings from import_xls.import_forms import google_address +def to_int(val): + """ + Reverse function to get_int + return None if value isnt integer + """ + try: + return int(val) + except ValueError: + return None + +def to_country(value): + try: + #query = get_translation_aware_manager(Country) + #country = query.filter(name=value)[0] + country = Country.objects.filter(translations__name=value)[0] + return country + except IndexError: + return None + +def to_city(value, lang, country): + try: + # get city by name + #objects = get_translation_aware_manager(City) + # except IndexError if no found + city = City.objects.filter(translations__name=value, country=country)[0] + return city + except IndexError: + return None + +from theme.models import Theme, Tag +def to_theme(obj, value): + if isinstance(value, float) or isinstance(value, int): + if (value - int(value) > 0): + value = str(value) + else: + value = str(int(value)) + theme_ids = value.split('.') + else: + theme_ids = value.split(',') + theme_objects = [] + for id in theme_ids: + try: + theme = Theme.objects.language('ru').get(id=int(id)) + theme_objects.append(theme) + obj.theme.add(theme) + except Theme.DoesNotExist, ValueError: + pass + + + return theme_objects + +from hvad.utils import get_translation_aware_manager +def to_tag(obj,value): + if value == [""]: + return None + + names = value.split(',') + tags = [] + for name in names: + objects = get_translation_aware_manager(Tag) + tag = objects.filter(name=name) + #tag = Tag.objects.language('ru').filter(transations__name=name) + if tag: + tags.append(tag[0]) + obj.tag.add(tag[0]) + else: + continue + return tags + +import time +def to_date(value): + if not value: + return None + + if isinstance(value, unicode) or isinstance(value, str): + + t = time.strptime(value, "%d.%m.%Y") + if isinstance(value, float): + t = xlrd.xldate_as_tuple(value, 0)+(0,0,0) + + return time.strftime("%Y-%m-%d", t) + +def to_currency(value): + if value=='USD': + return value + if value=='EUR': + return value + if value=='RUB': + return 'RUB' + return 'USD' + +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_logo(obj, value, purpose): + """ + if not obj.id: + return None + """ + + + urls = value.split(';') + + + for url in urls: + + + + + if url[0]!=('/'): + url = '/'+url + url = 'http://www.expomap.ru'+url + + 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 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 PlaceExposition +def to_place(value): + try: + place = PlaceExposition.objects.get(id=value) + return place + except: + + return None +from exposition.models import BIT_AUDIENCE +def to_audience(value, model=Exposition): + if value: + l = value.split(', ') + aud = {'Trade visitors':'experts', 'Trade visitors and Public':'experts and consumers', + 'General public': 'general public'} + if l: + new_list = [] + for value in l: + for item1, item2 in BIT_AUDIENCE: + if aud.get(value) == item2: + new_list.append(item1) + if new_list: + + return reduce(lambda x,y: x|y, (getattr(model.audience, item) for item in new_list)) + return 0 + +def to_periodic(value): + per = {'Оnce a year': 1.0, 'Every 2 years':0.5, 'Twice a year':2.0} + return per.get(value, 0) + +from organiser.models import Organiser +def to_organiser(obj, value): + org = Organiser.objects.filter(translations__name=value) + if org: + obj.organiser.add(org[0]) + else: + org = Organiser() + org.translate('ru') + org.name = value + org.save() + + +event_sett = { + u'ID':{u'field': u'id', u'func': to_int}, + 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', 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_organiser, u'method': True},#### + u'Организатор №2':{u'field': u'organiser', u'func': to_organiser, u'method': True},#### + 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'logo', u'func': save_logo, u'method': True, u'purpose': 'logo'}, + 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'currency', u'func': to_currency}, + # + u'Посетители_билет (1 день)':{u'field': u'price_day', u'func': to_int}, + u'Посетители_билет (все дни)':{u'field': u'price_all', u'func': to_int}, + #u'Условия':{u'field': u'periodic', u'func': unicode}, + u'Посетители_билет (1 день)(на стойке)':{u'field': u'price_day_bar', u'func': to_int},##?? + u'Посетители_билет (все дни)(на стойке)':{u'field': u'price_all_bar', u'func': to_int},##?? + #u'Условия':{u'field': u'periodic', u'func': unicode},##?? + #u'Примечание':{u'field': u'periodic', 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'periodic', u'func': unicode},##?? + u'Площадь':{u'field': u'periodic', 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_open_area', u'func': to_int}, + u'Регистрационный взнос':{u'field': u'registration_payment', u'func': to_int}, + #u'Примечание':{u'field': u'periodic', u'func': unicode}, + u'Крайний срок подачи заявки':{u'field': u'application_deadline', u'func': to_date}, + u'UFI':{u'field': u'quality_label', u'func': bool, },## + u'РСВЯ':{u'field': u'quality_label', u'func': bool},## + u'EXPORATING':{u'field': u'quality_label', u'func': bool},## + u'Отменена':{u'field': u'canceled', u'func': bool}, + u'ExpoHIT':{u'field': u'expohit', u'func': bool}, + #u'Фото':{u'field': u'photo', u'func': save_photo, u'method': True}, + +} + class Command(BaseCommand): def handle(self, *args, **options): @@ -17,7 +288,7 @@ class Command(BaseCommand): sheet = book.sheet_by_index(0) row_list = [sheet.row_values(row_number) for row_number in range(sheet.nrows)] labels = [label for label in row_list[0]] - print(len(row_list)) + for row_number, row in enumerate(row_list): @@ -46,6 +317,7 @@ class Command(BaseCommand): methods = [] flag = False for col_number, cell in enumerate(row): + # go through row cells # field name current cell label = labels[col_number] @@ -82,9 +354,19 @@ class Command(BaseCommand): print('error city') flag = True continue - setattr(object, field_name, value) + if not field_name=='quality_label': + setattr(object, field_name, value) + else: + if value: + if setting.get('l') == 'ufi': + object.quality_label.ufi = True + if setting.get('l') == 'rsva': + object.quality_label.rsva = True + if setting.get('l') == 'exporating': + object.quality_label.exporating = True + + - object.currency = 'USD' if not flag: try: print('pre save %s'% str(object)) @@ -96,7 +378,6 @@ class Command(BaseCommand): else: print('bad city') - for method in methods: func = method['func'] if method.get('purpose'): @@ -108,4 +389,4 @@ class Command(BaseCommand): try: func(object, method['value']) except: - continue \ No newline at end of file + continue diff --git a/functions/custom_views.py b/functions/custom_views.py index f92d3c69..06898b90 100644 --- a/functions/custom_views.py +++ b/functions/custom_views.py @@ -284,7 +284,8 @@ class ExpoListView(ExpoMixin, ListView): self.params = params - return query + + return query.order_by('data_begin') def get_context_data(self, **kwargs): context = super(ExpoListView, self).get_context_data(**kwargs) diff --git a/import_xls/excel_settings.py b/import_xls/excel_settings.py index a5874d26..b510049b 100644 --- a/import_xls/excel_settings.py +++ b/import_xls/excel_settings.py @@ -528,22 +528,6 @@ event_sett = { u'Фото':{u'field': u'photo', u'func': save_photo, u'method': True}, - - - - - - - - - - - - - - - - # } import_settings={ diff --git a/media/imgs/149.jpeg b/media/imgs/149.jpeg new file mode 100644 index 00000000..3fac9105 Binary files /dev/null and b/media/imgs/149.jpeg differ diff --git a/media/imgs/Atlantic City In-Water Power Boat Show.JPG b/media/imgs/Atlantic City In-Water Power Boat Show.JPG new file mode 100644 index 00000000..2fb1b9da Binary files /dev/null and b/media/imgs/Atlantic City In-Water Power Boat Show.JPG differ diff --git a/media/imgs/Automechanika 2012.jpeg b/media/imgs/Automechanika 2012.jpeg new file mode 100644 index 00000000..5404aaf3 Binary files /dev/null and b/media/imgs/Automechanika 2012.jpeg differ diff --git a/media/imgs/Bio 2014.png b/media/imgs/Bio 2014.png new file mode 100644 index 00000000..25480495 Binary files /dev/null and b/media/imgs/Bio 2014.png differ diff --git a/media/imgs/CEF Summer Chengdu 2014.jpeg b/media/imgs/CEF Summer Chengdu 2014.jpeg new file mode 100644 index 00000000..4f435ac0 Binary files /dev/null and b/media/imgs/CEF Summer Chengdu 2014.jpeg differ diff --git a/media/imgs/CWIEME Berlin.jpeg b/media/imgs/CWIEME Berlin.jpeg new file mode 100644 index 00000000..56929a3b Binary files /dev/null and b/media/imgs/CWIEME Berlin.jpeg differ diff --git a/media/imgs/CeBIT India.jpeg b/media/imgs/CeBIT India.jpeg new file mode 100644 index 00000000..c65b5020 Binary files /dev/null and b/media/imgs/CeBIT India.jpeg differ diff --git a/media/imgs/Cloud World Forum.1.JPG b/media/imgs/Cloud World Forum.1.JPG new file mode 100644 index 00000000..94b68696 Binary files /dev/null and b/media/imgs/Cloud World Forum.1.JPG differ diff --git a/media/imgs/Cloud World Forum.2.JPG b/media/imgs/Cloud World Forum.2.JPG new file mode 100644 index 00000000..94b68696 Binary files /dev/null and b/media/imgs/Cloud World Forum.2.JPG differ diff --git a/media/imgs/Cloud World Forum.3.JPG b/media/imgs/Cloud World Forum.3.JPG new file mode 100644 index 00000000..94b68696 Binary files /dev/null and b/media/imgs/Cloud World Forum.3.JPG differ diff --git a/media/imgs/Cloud World Forum.JPG b/media/imgs/Cloud World Forum.JPG new file mode 100644 index 00000000..94b68696 Binary files /dev/null and b/media/imgs/Cloud World Forum.JPG differ diff --git a/media/imgs/Coffee Fest Portland.JPG b/media/imgs/Coffee Fest Portland.JPG new file mode 100644 index 00000000..564c820c Binary files /dev/null and b/media/imgs/Coffee Fest Portland.JPG differ diff --git a/media/imgs/Construct India.1.png b/media/imgs/Construct India.1.png new file mode 100644 index 00000000..efb2e825 Binary files /dev/null and b/media/imgs/Construct India.1.png differ diff --git a/media/imgs/Construct India.2.png b/media/imgs/Construct India.2.png new file mode 100644 index 00000000..efb2e825 Binary files /dev/null and b/media/imgs/Construct India.2.png differ diff --git a/media/imgs/Construct India.3.png b/media/imgs/Construct India.3.png new file mode 100644 index 00000000..efb2e825 Binary files /dev/null and b/media/imgs/Construct India.3.png differ diff --git a/media/imgs/Construct India.png b/media/imgs/Construct India.png new file mode 100644 index 00000000..efb2e825 Binary files /dev/null and b/media/imgs/Construct India.png differ diff --git a/media/imgs/EMS World Expo.JPG b/media/imgs/EMS World Expo.JPG new file mode 100644 index 00000000..0a84aebb Binary files /dev/null and b/media/imgs/EMS World Expo.JPG differ diff --git a/media/imgs/Ecoc2014.JPG b/media/imgs/Ecoc2014.JPG new file mode 100644 index 00000000..f7acebb6 Binary files /dev/null and b/media/imgs/Ecoc2014.JPG differ diff --git a/media/imgs/FIMI2014.png b/media/imgs/FIMI2014.png new file mode 100644 index 00000000..3c6258d7 Binary files /dev/null and b/media/imgs/FIMI2014.png differ diff --git a/media/imgs/Fastener Fair India.1.png b/media/imgs/Fastener Fair India.1.png new file mode 100644 index 00000000..6317222c Binary files /dev/null and b/media/imgs/Fastener Fair India.1.png differ diff --git a/media/imgs/Fastener Fair India.2.png b/media/imgs/Fastener Fair India.2.png new file mode 100644 index 00000000..6317222c Binary files /dev/null and b/media/imgs/Fastener Fair India.2.png differ diff --git a/media/imgs/Fastener Fair India.3.png b/media/imgs/Fastener Fair India.3.png new file mode 100644 index 00000000..6317222c Binary files /dev/null and b/media/imgs/Fastener Fair India.3.png differ diff --git a/media/imgs/Fastener Fair India.png b/media/imgs/Fastener Fair India.png new file mode 100644 index 00000000..6317222c Binary files /dev/null and b/media/imgs/Fastener Fair India.png differ diff --git a/media/imgs/Fatex.jpeg b/media/imgs/Fatex.jpeg new file mode 100644 index 00000000..1a4ed43e Binary files /dev/null and b/media/imgs/Fatex.jpeg differ diff --git a/media/imgs/Fine-Food-India.1.png b/media/imgs/Fine-Food-India.1.png new file mode 100644 index 00000000..1ed27000 Binary files /dev/null and b/media/imgs/Fine-Food-India.1.png differ diff --git a/media/imgs/Fine-Food-India.2.png b/media/imgs/Fine-Food-India.2.png new file mode 100644 index 00000000..1ed27000 Binary files /dev/null and b/media/imgs/Fine-Food-India.2.png differ diff --git a/media/imgs/Fine-Food-India.3.png b/media/imgs/Fine-Food-India.3.png new file mode 100644 index 00000000..1ed27000 Binary files /dev/null and b/media/imgs/Fine-Food-India.3.png differ diff --git a/media/imgs/Fine-Food-India.png b/media/imgs/Fine-Food-India.png new file mode 100644 index 00000000..1ed27000 Binary files /dev/null and b/media/imgs/Fine-Food-India.png differ diff --git a/media/imgs/FlowEx China 2014.jpeg b/media/imgs/FlowEx China 2014.jpeg new file mode 100644 index 00000000..4752963d Binary files /dev/null and b/media/imgs/FlowEx China 2014.jpeg differ diff --git a/media/imgs/GLEE_Logo_RGB_Square.png b/media/imgs/GLEE_Logo_RGB_Square.png new file mode 100644 index 00000000..1e188c6a Binary files /dev/null and b/media/imgs/GLEE_Logo_RGB_Square.png differ diff --git a/media/imgs/Great Tennessee Air Show.1.png b/media/imgs/Great Tennessee Air Show.1.png new file mode 100644 index 00000000..626104ba Binary files /dev/null and b/media/imgs/Great Tennessee Air Show.1.png differ diff --git a/media/imgs/Great Tennessee Air Show.2.png b/media/imgs/Great Tennessee Air Show.2.png new file mode 100644 index 00000000..626104ba Binary files /dev/null and b/media/imgs/Great Tennessee Air Show.2.png differ diff --git a/media/imgs/Great Tennessee Air Show.3.png b/media/imgs/Great Tennessee Air Show.3.png new file mode 100644 index 00000000..626104ba Binary files /dev/null and b/media/imgs/Great Tennessee Air Show.3.png differ diff --git a/media/imgs/Great Tennessee Air Show.png b/media/imgs/Great Tennessee Air Show.png new file mode 100644 index 00000000..626104ba Binary files /dev/null and b/media/imgs/Great Tennessee Air Show.png differ diff --git a/media/imgs/Guangzhou International Lighting Exhibition 2012.jpeg b/media/imgs/Guangzhou International Lighting Exhibition 2012.jpeg new file mode 100644 index 00000000..40c9055b Binary files /dev/null and b/media/imgs/Guangzhou International Lighting Exhibition 2012.jpeg differ diff --git a/media/imgs/HOGA.png b/media/imgs/HOGA.png new file mode 100644 index 00000000..192a5f1d Binary files /dev/null and b/media/imgs/HOGA.png differ diff --git a/media/imgs/Hong Kong Food Expo.1.jpeg b/media/imgs/Hong Kong Food Expo.1.jpeg new file mode 100644 index 00000000..b0d234d3 Binary files /dev/null and b/media/imgs/Hong Kong Food Expo.1.jpeg differ diff --git a/media/imgs/Hong Kong Food Expo.2.jpeg b/media/imgs/Hong Kong Food Expo.2.jpeg new file mode 100644 index 00000000..b0d234d3 Binary files /dev/null and b/media/imgs/Hong Kong Food Expo.2.jpeg differ diff --git a/media/imgs/Hong Kong Food Expo.3.jpeg b/media/imgs/Hong Kong Food Expo.3.jpeg new file mode 100644 index 00000000..b0d234d3 Binary files /dev/null and b/media/imgs/Hong Kong Food Expo.3.jpeg differ diff --git a/media/imgs/Hong Kong Food Expo.jpeg b/media/imgs/Hong Kong Food Expo.jpeg new file mode 100644 index 00000000..b0d234d3 Binary files /dev/null and b/media/imgs/Hong Kong Food Expo.jpeg differ diff --git a/media/imgs/hm13_logo_en_col.png b/media/imgs/hm13_logo_en_col.png new file mode 100644 index 00000000..ec23489b Binary files /dev/null and b/media/imgs/hm13_logo_en_col.png differ diff --git a/media/imgs/logo_cosmoprof.png b/media/imgs/logo_cosmoprof.png new file mode 100644 index 00000000..1f7a400b Binary files /dev/null and b/media/imgs/logo_cosmoprof.png differ diff --git a/media/import/expositions_ru.xlsx b/media/import/expositions_ru.xlsx index 1d8a850d..d6e3b79e 100644 Binary files a/media/import/expositions_ru.xlsx and b/media/import/expositions_ru.xlsx differ diff --git a/templates/client/includes/menu.html b/templates/client/includes/menu.html index 3529c3ff..a409c1c4 100644 --- a/templates/client/includes/menu.html +++ b/templates/client/includes/menu.html @@ -16,7 +16,7 @@