diff options
| -rw-r--r-- | archaeological_operations/tests.py | 3 | ||||
| -rw-r--r-- | ishtar_common/data_importer.py | 8 | 
2 files changed, 8 insertions, 3 deletions
| diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 484e2b259..bbe92b3c8 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -162,8 +162,11 @@ class ImportOperationTest(TestCase):                           sorted([p.section for p in last_parcels]))          last_ope = models.Operation.objects.order_by('-pk').all()[0]          towns_ope = last_ope.towns.all() +        imported = [imp for acc, imp in impt.get_all_imported()]          for p in last_parcels:              self.assertTrue(p.town in towns_ope) +            self.assertTrue(p in imported) +        self.assertEqual(len(imported), len(last_parcels))          self.assertEqual(models.Parcel.objects.get(parcel_number='55',                                                     section='YY').external_id,                          'YY55') diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index 1cdb167bc..2a20c245a 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -727,7 +727,8 @@ class Importer(object):                  for k in data['defaults']:                      setattr(t_obj, k, data['defaults'][k])                  t_obj.save() -            if self.import_instance and hasattr(t_obj, 'imports'): +            if self.import_instance and hasattr(t_obj, 'imports') \ +               and created:                  t_obj.imports.add(self.import_instance)          for formater, val in self._post_processing: @@ -893,7 +894,7 @@ class Importer(object):                                      v, created = model.objects.get_or_create(                                                                              **v)                                      if self.import_instance \ -                                       and hasattr(v, 'imports'): +                                       and hasattr(v, 'imports') and created:                                          v.imports.add(self.import_instance)                                      m2ms.append((attribute, v))                  elif hasattr(field_object, 'rel') and field_object.rel and \ @@ -933,7 +934,8 @@ class Importer(object):                      dct = create_dict.copy()                      dct['defaults'] = defaults                      obj, created = cls.objects.get_or_create(**dct) -                    if self.import_instance and hasattr(obj, 'imports'): +                    if self.import_instance and hasattr(obj, 'imports') \ +                       and created:                          obj.imports.add(self.import_instance)                  except IntegrityError as e:                      raise IntegrityError(e.message) | 
