summaryrefslogtreecommitdiff
path: root/ishtar_common/data_importer.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-07-14 17:39:34 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-07-14 17:39:34 +0200
commit7db4ca0a344c2e2890170f3fd08c961f7da9da44 (patch)
tree9cd31118a6d99df4b53f4b63e848e84de228b26b /ishtar_common/data_importer.py
parent3ba308112bfbe261533e6b72bbd0e09269f2e57d (diff)
downloadIshtar-7db4ca0a344c2e2890170f3fd08c961f7da9da44.tar.bz2
Ishtar-7db4ca0a344c2e2890170f3fd08c961f7da9da44.zip
Imports: more precise management of files
Diffstat (limited to 'ishtar_common/data_importer.py')
-rw-r--r--ishtar_common/data_importer.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index 908aa84c4..b669995e3 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -1232,11 +1232,16 @@ class Importer(object):
self.get_field(model, k, v, m2m_m2ms, c_c_path,
new_created)
if '__force_new' in v:
+ created = v.pop('__force_new')
+ key = u";".join([u"{}-{}".format(k, v[k])
+ for k in sorted(v.keys())])
# only one forced creation
- if attribute in new_created:
+ if attribute in new_created \
+ and key in new_created[attribute]:
continue
- new_created.append(attribute)
- created = v.pop('__force_new')
+ if attribute not in new_created:
+ new_created[attribute] = []
+ new_created[attribute].append(key)
has_values = bool([1 for k in v if v[k]])
if has_values:
v = model.objects.create(**v)
@@ -1248,14 +1253,19 @@ class Importer(object):
# "File" type is a temp object and can be different
# for the same filename - it must be treated
# separatly
- for k in v.keys():
- if type(v[k]) == File:
+ for field in model._meta.fields:
+ k = field.name
+ # attr_class est un attribut de FileField
+ if hasattr(field, 'attr_class') and k in v:
extra_fields[k] = v.pop(k)
v, created = model.objects.get_or_create(
**v)
+ changed = False
for k in extra_fields.keys():
- setattr(v, k, extra_fields[k])
- if extra_fields:
+ if extra_fields[k]:
+ changed = True
+ setattr(v, k, extra_fields[k])
+ if changed:
v.save()
for att, objs in m2m_m2ms:
if type(objs) not in (list, tuple):
@@ -1289,7 +1299,7 @@ class Importer(object):
c_path = path[:]
# get all related fields
- new_created = []
+ new_created = {}
for attribute in list(data.keys()):
c_c_path = c_path[:]
if not attribute: