You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

180 lines
7.0 KiB

# -*- coding: utf-8 -*-
import xlwt
import datetime
def get_bool(value):
if value:
return 1
return 0
def get_int(value):
if not value:
return ''
return value
def get_audience(value):
if not value:
return 'Не выбрано'
elif value == 'experts':
return 'Специалисты'
elif value == 'experts and consumers':
return 'Специалисты и потребители'
elif value == 'general public':
return 'Широкая публика'
else:
return ''
field_settings = [
{'name': 'id', 'verbose_name': 'id', 'type': get_int, 'width':1500},
{'name': 'url', 'verbose_name': 'url', 'type': str},
{'name': 'name', 'verbose_name': 'Имя', 'type': str, 'width':8000,},
{'name': 'data_begin', 'verbose_name': 'Дата начала', 'type': str},
{'name': 'data_end', 'verbose_name': 'Дата окончания', 'type': str},
{'name': 'main_title', 'verbose_name': 'Краткое описание', 'type': str},
{'name': 'description', 'verbose_name': 'Описание', 'type': str},
{'name': 'audience', 'verbose_name': 'Аудитория', 'type': get_audience},
{'name': 'country', 'verbose_name': 'Страна', 'type': str},
{'name': 'city', 'verbose_name': 'Город', 'type': str},
{'name': 'periodic', 'verbose_name': 'Периодичность', 'type': str},
{'name': 'web_page', 'verbose_name': 'Веб страница', 'type': str},
{'name': 'time', 'verbose_name': 'Время проведения', 'type': str},
{'name': 'products', 'verbose_name': 'Экспонируемые продукты', 'type': str},
{'name': 'foundation_year', 'verbose_name': 'Год основания', 'type': get_int},
{'name': 'tax', 'verbose_name': 'Налог включен', 'type': get_bool, 'width':1000},
{'name': 'currency', 'verbose_name': 'Валюта', 'type': str},
{'name': 'max_price', 'verbose_name': 'Максимальная цена', 'type': get_int},
{'name': 'min_price', 'verbose_name': 'Минимальная цена', 'type': get_int},
{'name': 'registration_payment', 'verbose_name': 'Регистрационный взнос', 'type': get_int},
{'name': 'min_closed_area', 'verbose_name': 'Минимальная цена закрытой НЕ оборудованной площади', 'type': get_int},
{'name': 'max_closed_area', 'verbose_name': 'Максимальная цена закрытой НЕ оборудованной площади', 'type': get_int},
{'name': 'min_closed_equipped_area', 'verbose_name': 'Минимальная цена закрытой оборудованной площади ', 'type': get_int},
{'name': 'max_closed_equipped_area', 'verbose_name': 'Максимальная цена закрытой оборудованной площади', 'type': get_int},
{'name': 'min_open_area', 'verbose_name': 'Минимальная цена закрытой площади', 'type': get_int},
{'name': 'max_open_area', 'verbose_name': 'Максимальная цена открытой площади', 'type': get_int},
{'name': 'min_area', 'verbose_name': 'Минимальная площадь', 'type': get_int},
{'name': 'max_area', 'verbose_name': 'Максимальная площадь', 'type': get_int},
{'name': 'is_published', 'verbose_name': 'Опубликована', 'type': get_bool, 'width':1000},
{'name': 'canceled_by_administrator', 'verbose_name': 'Отменена администратором', 'type': get_bool, 'width':1000}
]
def to_int(val):
"""
Reverse function to get_int
return None if value isnt integer
"""
try:
return int(val)
except ValueError:
return None
from country.models import Country
from hvad.utils import get_translation_aware_manager
def to_country(value):
try:
query = get_translation_aware_manager(Country)
country = query.filter(name=value)[0]
return country
except IndexError:
return None
from city.models import City
def to_city(value, lang, country):
try:
# get city by name
objects = get_translation_aware_manager(City)
# except IndexError if no found
city = objects.filter(name=value)[0]
return city
except IndexError:
# not found
# try to create new city
city = City(country=country)
city.translate(lang)
city.name = value
city.save()
return city
def to_audience(value):
try:
if value == 'Специалисты':
return 'experts'
elif value == 'Специалисты и потребители':
return 'experts and consumers'
elif value == 'Широкая публика':
return 'general public'
else:
return 'None'
except:
return 'None'
import_settings={
'name': {'func': str, },
'url': {'func': str},
'data_begin': {'func': str},
'data_end': {'func': str},
'main_title': {'func': str},
'description': {'func': str},
'audience': {'func': to_audience},
'country': {'func': to_country},
'city': {'func': to_city, 'extra_values': 'country'},
'periodic': {'func': str},
'web_page': {'func': str},
'time': {'func': str},
'products': {'func': str},
'foundation_year': {'func': to_int},
'tax': {'func': bool},
'currency': {'func': str},
'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}
}
"""
def get_cell(field_name):
return {#'id': int(value),
'url': str,
'name': str,
'data_begin': str,
'data_end': str,
'main_title': str,
'description': str,
'audience': to_audience,
'country': to_country,
'city': to_city,
#'periodic': str(value),
'web_page': str,
'time': str,
'products': str,
'foundation_year': to_int,
'tax': bool,
'currency': str,
'max_price': to_int,
'min_price': to_int,
'registration_payment': to_int,
'min_closed_area': to_int,
'max_closed_area': to_int,
'min_closed_equipped_area': to_int,
'max_closed_equipped_area': to_int,
'min_open_area': to_int,
'max_open_area': to_int,
'min_area': to_int,
'max_area': to_int,
'is_published': bool,
'canceled_by_administrator': bool
}.get(field_name)
"""