diff options
| -rw-r--r-- | archaeological_operations/models.py | 2 | ||||
| -rw-r--r-- | archaeological_warehouse/models.py | 6 | ||||
| -rw-r--r-- | ishtar_common/models.py | 40 | 
3 files changed, 25 insertions, 23 deletions
| diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index b547db375..3538db2f8 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -1546,7 +1546,7 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem,          for res in q.all():              label = str(res['object_types__label'])              if label == 'None': -                label = _("No type") +                label = str(_("No type"))              nbs.append(                  (label,                   Find.objects.filter( diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index cc3542c79..ba53dc49f 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -284,16 +284,14 @@ class Warehouse(Address, DocumentItem, GeoItem, QRCodeItem, DashboardFormItem,      @property      def number_of_finds_by_place(self, update=False): -        return self._get_or_set_stats('_number_of_finds_by_place', update, -                                      settings.CACHE_SMALLTIMEOUT) +        return self._get_or_set_stats('_number_of_finds_by_place', update)      def _number_of_containers_by_place(self):          return self._number_of_items_by_place(Container)      @property      def number_of_containers_by_place(self, update=False): -        return self._get_or_set_stats('_number_of_containers_by_place', update, -                                      settings.CACHE_SMALLTIMEOUT) +        return self._get_or_set_stats('_number_of_containers_by_place', update)      def merge(self, item, keep_old=False):          # do not recreate missing divisions diff --git a/ishtar_common/models.py b/ishtar_common/models.py index ffa5323dd..7e62417ac 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -3193,15 +3193,15 @@ class StatsCache(models.Model):  def update_stats(statscache, item, funcname):      if not settings.USE_BACKGROUND_TASK: -        raw_value = getattr(item, funcname)() -        if not isinstance(raw_value, dict): -            values = {"_raw_": raw_value} -        else: -            values = raw_value -        statscache.values = values +        current_values = statscache.values +        if not current_values: +            current_values = {} +        value = getattr(item, funcname)() +        current_values[funcname] = value +        statscache.values = current_values          statscache.updated = datetime.datetime.now()          statscache.save() -        return values +        return current_values      now = datetime.datetime.now()      if statscache.update_requested and ( @@ -3226,16 +3226,17 @@ def _update_stats(app, model, model_pk, funcname):          item = model.objects.get(pk=model_pk)      except model.DoesNotExist:          return -    raw_value = getattr(item, funcname)() -    if not isinstance(raw_value, dict): -        values = {"_raw_": raw_value} -    else: -        values = raw_value -    sc.values = values +    current_values = sc.values +    if not current_values: +        current_values = {} +    value = getattr(item, funcname)() +    current_values[funcname] = value + +    sc.values = current_values      sc.update_requested = None      sc.updated = datetime.datetime.now()      sc.save() -    sc, __ = StatsCache.objects.get_or_create( +    StatsCache.objects.get_or_create(          model=model_name, model_pk=model_pk      ) @@ -3253,14 +3254,17 @@ class DashboardFormItem(object):              model=model_name, model_pk=self.pk          )          now = datetime.datetime.now() -        if not update and sc.values and ( +        values = {} +        from_cache = False +        if not update and sc.values and funcname in sc.values and (                  sc.updated + datetime.timedelta(seconds=timeout)) > now:              values = sc.values              from_cache = True -        else: +        if funcname not in values:              values = update_stats(sc, self, funcname) -            from_cache = False -        if "_raw_" in values: +        if funcname in values: +            values = values[funcname] +        elif "_raw_" in values:              values = values["_raw_"]          if expected_type is not None and not isinstance(values, expected_type):              if from_cache: | 
