фикс импорта событий

remotes/origin/HEAD
Slava Kyrachevsky 9 years ago
parent cef8a99b37
commit 2a3079dbd8
  1. 2
      apps/exposition/admin.py
  2. 4
      apps/import_xls/excel_settings.py
  3. 64
      apps/import_xls/import_forms.py
  4. 48
      apps/import_xls/utils.py

@ -278,7 +278,7 @@ class ExpositionView(AdminView):
'expohit': obj.expohit, 'discount': obj.discount,
'canceled': obj.canceled, 'moved': obj.moved, 'logo': obj.logo,
'visitors': obj.visitors, 'members': obj.members,
'audience':[item for item, bool in obj.audience.all() if bool],
'audience': [item for item in obj.audience.all()],
'quality_label': [item for item, bool in obj.quality_label if bool],
'place_alt': obj.place_alt}

@ -284,7 +284,7 @@ event_sett = {
u'Основные темы': {u'field': u'main_themes', u'func': unicode},
u'Условия и скидка': {u'field': u'discount_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'audience', u'func': to_audience, u'method': True},
u'Официальный веб-сайт': {u'field': u'web_page', u'func': to_url},
u'Линк на регистрацию': {u'field': u'link', u'func': to_url},
u'Экспонируемые продукты': {u'field': u'products', u'func': unicode},
@ -511,4 +511,4 @@ import_settings={
'is_published': {'func': bool},
'canceled_by_administrator': {'func': bool},
'types': {'func': to_theme_type}
}
}

@ -420,7 +420,6 @@ class ImportEventForm(ImportForm):
if setting is None:
continue
if setting.get('method'):
# this cell contains data that must be written after creating object
if cell != "":
@ -549,40 +548,39 @@ class ImportEventForm(ImportForm):
list_dicts.append(d)
"""
# go through row cells
# field name current cell
field_name = field_names[col_number]
if field_name =='theme':
# need save object before saving manytomany field
#object.save()
setting = import_settings.get(field_name)
d[setting] = cell
"""
# go through row cells
# field name current cell
field_name = field_names[col_number]
if field_name =='theme':
# need save object before saving manytomany field
#object.save()
setting = import_settings.get(field_name)
d[setting] = cell
if setting is not None:
# if setting exist for this field
func = setting.get('func')
if func is not None:
extra_value = setting.get('extra_values')
if extra_value is not None:
# if setting has extra value then
# it is some field like city, theme, tag
# that has relation and can be created
# in function we add language(need for relation fields)
# and extra value from object (like for city need country)
if cell:
value = func(cell, lang, getattr(object, extra_value))
else:
value = None
else:
value = func(cell)
if value:
setattr(object, field_name, value)
"""
if setting is not None:
# if setting exist for this field
func = setting.get('func')
if func is not None:
extra_value = setting.get('extra_values')
if extra_value is not None:
# if setting has extra value then
# it is some field like city, theme, tag
# that has relation and can be created
# in function we add language(need for relation fields)
# and extra value from object (like for city need country)
if cell:
value = func(cell, lang, getattr(object, extra_value))
else:
value = None
else:
value = func(cell)
if value:
setattr(object, field_name, value)
"""
#object.save()
#object.save()

@ -6,9 +6,8 @@ from PIL import Image
from django.conf import settings
from django.utils import translation
from hvad.utils import get_translation_aware_manager
from bitfield import BitHandler
from place_exposition.models import PlaceExposition
from exposition.models import Exposition
from events.models import TargetAudience
from country.models import Country
from city.models import City
from theme.models import Theme, Tag
@ -134,32 +133,29 @@ def to_periodic(value):
return periodic.get(value, 0)
def to_audience(value, model=Exposition):
if value:
translation.activate('ru')
l = value.split(', ')
if l:
new_list = []
for value in l:
for item1, item2 in BIT_AUDIENCE:
if 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_audience(obj, value):
# new_list = []
# if value:
# translation.activate('ru')
# l = value.split(', ')
# target_audience = TargetAudience.objects.all()
# print l
# for value in l:
# for ta in target_audience:
# if value == ta.title:
# new_list.append(ta.pk)
# return new_list
translation.activate('ru')
target_audience = TargetAudience.objects.filter(title__in=value.split(', ')).values_list('pk', flat=True)
obj.audience.clear()
obj.audience.add(*TargetAudience.objects.filter(id__in=target_audience))
return None
def get_audience(value):
if isinstance(value, BitHandler):
l = [k for k, v in value.iteritems() if v]
if l:
new_list = []
for value in l:
for item1, item2 in BIT_AUDIENCE:
if value == item1:
new_list.append(unicode(item2))
return ', '.join(new_list)
return ''
new_list = [x.title for x in value.all()]
return ', '.join(new_list)
import types
def save_logo(obj, path):

Loading…
Cancel
Save