|
|
|
@ -1,6 +1,7 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
import xlwt |
|
|
|
from country.models import Country |
|
|
|
import datetime |
|
|
|
from city.models import City |
|
|
|
|
|
|
|
from theme.models import Theme, Tag |
|
|
|
|
|
|
|
|
|
|
|
def get_bool(value): |
|
|
|
def get_bool(value): |
|
|
|
if value: |
|
|
|
if value: |
|
|
|
@ -24,6 +25,25 @@ def get_audience(value): |
|
|
|
else: |
|
|
|
else: |
|
|
|
return '' |
|
|
|
return '' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_theme(value): |
|
|
|
|
|
|
|
objects = value.all() |
|
|
|
|
|
|
|
return ', '.join(str(obj) 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) for tag in tags if tag.theme == theme] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result += '['+','.join(tag_list)+']' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
field_settings = [ |
|
|
|
field_settings = [ |
|
|
|
{'name': 'id', 'verbose_name': 'id', 'type': get_int, 'width':1500}, |
|
|
|
{'name': 'id', 'verbose_name': 'id', 'type': get_int, 'width':1500}, |
|
|
|
{'name': 'url', 'verbose_name': 'url', 'type': str}, |
|
|
|
{'name': 'url', 'verbose_name': 'url', 'type': str}, |
|
|
|
@ -35,6 +55,8 @@ field_settings = [ |
|
|
|
{'name': 'audience', 'verbose_name': 'Аудитория', 'type': get_audience}, |
|
|
|
{'name': 'audience', 'verbose_name': 'Аудитория', 'type': get_audience}, |
|
|
|
{'name': 'country', 'verbose_name': 'Страна', 'type': str}, |
|
|
|
{'name': 'country', 'verbose_name': 'Страна', 'type': str}, |
|
|
|
{'name': 'city', 'verbose_name': 'Город', 'type': str}, |
|
|
|
{'name': 'city', 'verbose_name': 'Город', 'type': str}, |
|
|
|
|
|
|
|
{'name': 'theme', 'verbose_name': 'Тематика', 'type': get_theme}, |
|
|
|
|
|
|
|
{'name': 'tag', 'verbose_name': 'Теги', 'type': get_tag}, |
|
|
|
{'name': 'periodic', 'verbose_name': 'Периодичность', 'type': str}, |
|
|
|
{'name': 'periodic', 'verbose_name': 'Периодичность', 'type': str}, |
|
|
|
{'name': 'web_page', 'verbose_name': 'Веб страница', 'type': str}, |
|
|
|
{'name': 'web_page', 'verbose_name': 'Веб страница', 'type': str}, |
|
|
|
{'name': 'time', 'verbose_name': 'Время проведения', 'type': str}, |
|
|
|
{'name': 'time', 'verbose_name': 'Время проведения', 'type': str}, |
|
|
|
@ -70,7 +92,7 @@ def to_int(val): |
|
|
|
except ValueError: |
|
|
|
except ValueError: |
|
|
|
return None |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
from country.models import Country |
|
|
|
|
|
|
|
from hvad.utils import get_translation_aware_manager |
|
|
|
from hvad.utils import get_translation_aware_manager |
|
|
|
def to_country(value): |
|
|
|
def to_country(value): |
|
|
|
try: |
|
|
|
try: |
|
|
|
@ -81,7 +103,7 @@ def to_country(value): |
|
|
|
return None |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from city.models import City |
|
|
|
|
|
|
|
def to_city(value, lang, country): |
|
|
|
def to_city(value, lang, country): |
|
|
|
try: |
|
|
|
try: |
|
|
|
# get city by name |
|
|
|
# get city by name |
|
|
|
@ -112,6 +134,30 @@ def to_audience(value): |
|
|
|
except: |
|
|
|
except: |
|
|
|
return 'None' |
|
|
|
return 'None' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def to_theme(value, lang='ru'): |
|
|
|
|
|
|
|
theme_names = value.split(', ') |
|
|
|
|
|
|
|
theme_objects = [] |
|
|
|
|
|
|
|
for name in theme_names: |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
theme = Theme.objects.get(name=name) |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
theme = Theme() |
|
|
|
|
|
|
|
theme.translate(lang) |
|
|
|
|
|
|
|
theme.name = name |
|
|
|
|
|
|
|
theme.save() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
theme_objects.append(theme) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return theme_objects |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#def to_tag(value): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import_settings={ |
|
|
|
import_settings={ |
|
|
|
'name': {'func': str, }, |
|
|
|
'name': {'func': str, }, |
|
|
|
'url': {'func': str}, |
|
|
|
'url': {'func': str}, |
|
|
|
@ -122,6 +168,7 @@ import_settings={ |
|
|
|
'audience': {'func': to_audience}, |
|
|
|
'audience': {'func': to_audience}, |
|
|
|
'country': {'func': to_country}, |
|
|
|
'country': {'func': to_country}, |
|
|
|
'city': {'func': to_city, 'extra_values': 'country'}, |
|
|
|
'city': {'func': to_city, 'extra_values': 'country'}, |
|
|
|
|
|
|
|
'theme': {'func': to_theme}, |
|
|
|
'periodic': {'func': str}, |
|
|
|
'periodic': {'func': str}, |
|
|
|
'web_page': {'func': str}, |
|
|
|
'web_page': {'func': str}, |
|
|
|
'time': {'func': str}, |
|
|
|
'time': {'func': str}, |
|
|
|
@ -142,39 +189,4 @@ import_settings={ |
|
|
|
'max_area': {'func': to_int}, |
|
|
|
'max_area': {'func': to_int}, |
|
|
|
'is_published': {'func': bool}, |
|
|
|
'is_published': {'func': bool}, |
|
|
|
'canceled_by_administrator': {'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) |
|
|
|
|
|
|
|
""" |
|
|
|
|