diff options
Diffstat (limited to 'ishtar_common/models_common.py')
| -rw-r--r-- | ishtar_common/models_common.py | 38 | 
1 files changed, 32 insertions, 6 deletions
| diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index fc73d707c..5a27f8ca9 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -1162,15 +1162,34 @@ class JsonData(models.Model, CachedGen):          if not force and value:              return value          choices = set() -        splitted_key = key[len("data__") :].split("__") -        q = cls.objects.filter(data__has_key=key[len("data__") :]).values_list( -            "data", flat=True +        splitted_key = key[len("data__"):].split("__") +        q = cls.objects.filter(data__has_key=key[len("data__"):]).values_list( +            "id", "data"          )          multi = False -        for value in q.all(): +        for pk, value in q.all():              for k in splitted_key:                  value = value[k]              if isinstance(value, list): +                # fix bad recording +                if len(value) == 1 and isinstance(value[0], str) \ +                        and value[0].startswith("['") \ +                        and value[0].endswith("']"): +                    value = value[0][2:-2] +                    value = value.split("', '") +                    obj = cls.objects.get(pk=pk) +                    data = copy.deepcopy(obj.data) +                    if len(splitted_key) == 1: +                        data[splitted_key[0]] = value +                    elif len(splitted_key) == 2: +                        data[splitted_key[0]][splitted_key[1]] = value +                    elif len(splitted_key) == 3: +                        data[splitted_key[0]][splitted_key[1]][splitted_key[2]] = value +                    else: +                        print("To many level in json field - fix not managed") +                    obj.data = data +                    obj._no_post_process = True +                    obj.save()                  multi = True                  for v in value:                      if v: @@ -1180,7 +1199,7 @@ class JsonData(models.Model, CachedGen):          c = []          if not multi:              c = [("", "")] -        c += [(v, v) for v in sorted(list(choices))] +        c += [(v, v) for v in sorted(list(choices)) if v]          cache.set(cache_key, c, settings.CACHE_SMALLTIMEOUT)          return c @@ -1712,7 +1731,14 @@ class BaseHistorizedItem(      def save(self, *args, **kwargs):          created = not self.pk -        if not getattr(self, "_no_last_modified_update", False) \ +        if getattr(self, "_no_post_process", False): +            self.skip_history_when_saving = True +            self._cached_label_checked = True +            self._post_saved_geo = True +            self._no_move = True + +        if (not getattr(self, "skip_history_when_saving", False) +            and not getattr(self, "_no_last_modified_update", False)) \                  or not self.last_modified:              self.last_modified = datetime.datetime.now()          if not getattr(self, "skip_history_when_saving", False): | 
