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

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, 'expohit': obj.expohit, 'discount': obj.discount,
'canceled': obj.canceled, 'moved': obj.moved, 'logo': obj.logo, 'canceled': obj.canceled, 'moved': obj.moved, 'logo': obj.logo,
'visitors': obj.visitors, 'members': obj.members, '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], 'quality_label': [item for item, bool in obj.quality_label if bool],
'place_alt': obj.place_alt} 'place_alt': obj.place_alt}

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

@ -420,7 +420,6 @@ class ImportEventForm(ImportForm):
if setting is None: if setting is None:
continue continue
if setting.get('method'): if setting.get('method'):
# this cell contains data that must be written after creating object # this cell contains data that must be written after creating object
if cell != "": if cell != "":
@ -549,40 +548,39 @@ class ImportEventForm(ImportForm):
list_dicts.append(d) 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
""" if setting is not None:
# go through row cells # if setting exist for this field
# field name current cell func = setting.get('func')
field_name = field_names[col_number] if func is not None:
if field_name =='theme': extra_value = setting.get('extra_values')
# need save object before saving manytomany field if extra_value is not None:
#object.save() # if setting has extra value then
setting = import_settings.get(field_name) # it is some field like city, theme, tag
d[setting] = cell # that has relation and can be created
if setting is not None: # in function we add language(need for relation fields)
# if setting exist for this field # and extra value from object (like for city need country)
func = setting.get('func') if cell:
if func is not None: value = func(cell, lang, getattr(object, extra_value))
extra_value = setting.get('extra_values') else:
if extra_value is not None: value = None
# if setting has extra value then else:
# it is some field like city, theme, tag value = func(cell)
# that has relation and can be created if value:
setattr(object, field_name, value)
# 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.conf import settings
from django.utils import translation from django.utils import translation
from hvad.utils import get_translation_aware_manager from hvad.utils import get_translation_aware_manager
from bitfield import BitHandler
from place_exposition.models import PlaceExposition from place_exposition.models import PlaceExposition
from exposition.models import Exposition from events.models import TargetAudience
from country.models import Country from country.models import Country
from city.models import City from city.models import City
from theme.models import Theme, Tag from theme.models import Theme, Tag
@ -134,32 +133,29 @@ def to_periodic(value):
return periodic.get(value, 0) return periodic.get(value, 0)
def to_audience(value, model=Exposition): def to_audience(obj, value):
if value: # new_list = []
translation.activate('ru') # if value:
l = value.split(', ') # translation.activate('ru')
if l: # l = value.split(', ')
new_list = [] # target_audience = TargetAudience.objects.all()
for value in l: # print l
for item1, item2 in BIT_AUDIENCE: # for value in l:
if value == item2: # for ta in target_audience:
new_list.append(item1) # if value == ta.title:
if new_list: # new_list.append(ta.pk)
return reduce(lambda x,y: x|y, (getattr(model.audience, item) for item in new_list)) # return new_list
return 0 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): def get_audience(value):
if isinstance(value, BitHandler): new_list = [x.title for x in value.all()]
l = [k for k, v in value.iteritems() if v] return ', '.join(new_list)
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 ''
import types import types
def save_logo(obj, path): def save_logo(obj, path):

Loading…
Cancel
Save