diff options
| -rw-r--r-- | CHANGES.md | 7 | ||||
| -rw-r--r-- | ishtar_common/data_importer.py | 40 | ||||
| -rw-r--r-- | ishtar_common/version.py | 4 | 
3 files changed, 32 insertions, 19 deletions
diff --git a/CHANGES.md b/CHANGES.md index 8ec170148..8dfeb312c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,13 @@ date: 2022-06-02  Ishtar changelog  ================ +v3.1.73 - 2022-06-07 +-------------------- + +### Features ### + +- Import: more "human" error messages +  v3.1.72 - 2022-06-02  -------------------- diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index ea3054110..64f478614 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -958,21 +958,11 @@ class Importer(object):          return True      def _get_improperly_conf_error(self, model): -        from ishtar_common.models import ImporterModel - -        cls_name = model.__module__ + "." + model.__name__ -        q = ImporterModel.objects.filter(klass=cls_name) -        if q.count(): -            cls_name = q.all()[0].name +        cls_name = str(model._meta.verbose_name)          return ImporterError(str(self.ERRORS["improperly_configured"]).format(cls_name))      def _get_does_not_exist_in_db_error(self, model, data): -        from ishtar_common.models import ImporterModel - -        cls_name = model.__module__ + "." + model.__name__ -        q = ImporterModel.objects.filter(klass=cls_name) -        if q.count(): -            cls_name = q.all()[0].name +        cls_name = str(model._meta.verbose_name)          values = ", ".join(["{}: {}".format(k, data[k]) for k in data])          raise ImporterError(              str(self.ERRORS["does_not_exist_in_db"]).format(cls_name, values) @@ -1719,7 +1709,8 @@ class Importer(object):                                  )                              )                          except Exception as e: -                            msg = str(_('Import error: {} - "{}".')).format(model, e) +                            msg = str(_('Import error: {} - "{}".')).format( +                                str(model._meta.verbose_name), e)                              raise ImporterError(msg)                      else:                          get_v = v.copy() @@ -1803,7 +1794,7 @@ class Importer(object):                          'Importer configuration error: field "{}" does not exist '                          "for {}."                      ) -                ).format(attribute, cls._meta.verbose_name) +                ).format(attribute, str(cls._meta.verbose_name))              )          if field_object.many_to_many:              try: @@ -1892,7 +1883,7 @@ class Importer(object):                  data = ""              raise ImporterError(                  "Erreur d'import %s %s, contexte : %s, erreur : %s" -                % (str(cls), str("__".join(path)), str(data), message) +                % (str(cls._meta.verbose_name), str("__".join(path)), str(data), message)              )          # image field is not serialized @@ -1935,6 +1926,7 @@ class Importer(object):          created = False          post_save_keys = [] +        get_by_unicity_key = False          try:              try:                  dct = {} @@ -1965,6 +1957,7 @@ class Importer(object):                  else:                      # manage UNICITY_KEYS - only level 1                      if not path and self.UNICITY_KEYS: +                        get_by_unicity_key = True                          for k in list(dct.keys()):                              if k not in self.UNICITY_KEYS and k != "defaults":                                  if dct[k]: @@ -2069,6 +2062,15 @@ class Importer(object):                  created = False                  if "defaults" in dct:                      dct.pop("defaults") +                if get_by_unicity_key: +                    data = {k: data[k] for k in self.UNICITY_KEYS if data.get(k, None)} +                    if not data: +                        data = str(_('unicity key(s) "{}" is/are missing')).format( +                            '" ; "'.join(self.UNICITY_KEYS)) +                        raise ImporterError( +                            str(_("Import error {}, {}")).format( +                                str(cls._meta.verbose_name), data) +                        )                  raise IntegrityError(str(e))                  # obj = cls.objects.filter(**dct).all()[0]              for key in post_save_keys: @@ -2150,8 +2152,12 @@ class Importer(object):              except UnicodeDecodeError:                  data = ""              raise ImporterError( -                "Erreur d'import %s %s, contexte : %s, erreur : %s" -                % (str(cls), str("__".join(path)), str(data), message) +                str( +                    _("Import error {}, path \"{}\", context : {}, error : {}") +                ).format( +                    str(cls._meta.verbose_name), str("__".join(path)), str(data), +                    message +                )              )          return obj, created diff --git a/ishtar_common/version.py b/ishtar_common/version.py index 024ffd0b6..276033fb0 100644 --- a/ishtar_common/version.py +++ b/ishtar_common/version.py @@ -1,5 +1,5 @@ -# 3.1.72 -VERSION = (3, 1, 72) +# 3.1.73 +VERSION = (3, 1, 73)  def get_version():  | 
