diff options
| -rw-r--r-- | ishtar_common/data_importer.py | 41 | 
1 files changed, 28 insertions, 13 deletions
| diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index 10957e74d..e11e72449 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -1400,20 +1400,35 @@ class Importer(object):          # get all related fields          new_created = {} -        for attribute in list(data.keys()): -            c_c_path = c_path[:] -            if not attribute: -                data.pop(attribute) -                continue -            if not data[attribute]: -                field_object, model, direct, m2m = \ -                    cls._meta.get_field_by_name(attribute) -                if m2m: +        try: +            for attribute in list(data.keys()): +                c_c_path = c_path[:] +                if not attribute:                      data.pop(attribute) -                continue -            if attribute != '__force_new': -                self.get_field(cls, attribute, data, m2ms, c_c_path, -                               new_created) +                    continue +                if not data[attribute]: +                    field_object, model, direct, m2m = \ +                        cls._meta.get_field_by_name(attribute) +                    if m2m: +                        data.pop(attribute) +                    continue +                if attribute != '__force_new': +                    self.get_field(cls, attribute, data, m2ms, c_c_path, +                                   new_created) +        except (ValueError, IntegrityError) as e: +            message = e.message +            try: +                message = e.message.decode('utf-8') +            except (UnicodeDecodeError, UnicodeDecodeError): +                message = '' +            try: +                data = unicode(data) +            except UnicodeDecodeError: +                data = '' +            raise ImporterError( +                "Erreur d'import %s %s, contexte : %s, erreur : %s" +                % (unicode(cls), unicode("__".join(path)), +                   unicode(data), message))          create_dict = copy.deepcopy(data)          for k in create_dict.keys(): | 
