diff options
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/views_item.py | 76 | 
1 files changed, 46 insertions, 30 deletions
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 6fd59624a..1a35e766e 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -1801,6 +1801,38 @@ def _get_json_stats(      return HttpResponse(data, content_type="application/json") +def _get_table_cols(data_type, own_table_cols, full, model): +    # list of table cols depending on configuration and data send +    if data_type == "json-map": +        return []  # only pk for map +    if own_table_cols: +        table_cols = own_table_cols +    else: +        if full: +            table_cols = [ +                field.name +                for field in model._meta.fields +                if field.name not in PRIVATE_FIELDS +            ] +            table_cols += [ +                field.name +                for field in model._meta.many_to_many +                if field.name not in PRIVATE_FIELDS +            ] +            if hasattr(model, "EXTRA_FULL_FIELDS"): +                table_cols += model.EXTRA_FULL_FIELDS +        else: +            tb_key = (getattr(model, "SLUG", None), "TABLE_COLS") +            if tb_key in settings.TABLE_COLS: +                table_cols = settings.TABLE_COLS[tb_key] +            else: +                table_cols = model.TABLE_COLS +    if callable(table_cols): +        table_cols = table_cols() +    table_cols = list(table_cols) +    return table_cols + +  DEFAULT_ROW_NUMBER = 10  # length is used by ajax DataTables requests  EXCLUDED_FIELDS = ["length"] @@ -2288,9 +2320,21 @@ def get_item(              return items          items = items.distinct() +        table_cols = _get_table_cols(data_type, own_table_cols, full, model) +        count_values = ["pk"] +        query_distinct_count = getattr(model, "QUERY_DISTINCT_COUNT", None) +        if query_distinct_count: +            for k, v in query_distinct_count.items(): +                if v in count_values: +                    continue +                for col in table_cols: +                    if col.startswith(k): +                        count_values.append(v) +                        break          try: -            items_nb = items.values("pk").aggregate(Count("pk"))["pk__count"] or 0 +            q = items.values(*count_values) +            items_nb = q.count() or 0          except ProgrammingError:              items_nb = 0          if count: @@ -2300,35 +2344,7 @@ def get_item(          if search_vector:  # for serialization              dct["search_vector"] = search_vector -        # table cols -        if own_table_cols: -            table_cols = own_table_cols -        else: -            if full: -                table_cols = [ -                    field.name -                    for field in model._meta.fields -                    if field.name not in PRIVATE_FIELDS -                ] -                table_cols += [ -                    field.name -                    for field in model._meta.many_to_many -                    if field.name not in PRIVATE_FIELDS -                ] -                if hasattr(model, "EXTRA_FULL_FIELDS"): -                    table_cols += model.EXTRA_FULL_FIELDS -            else: -                tb_key = (getattr(model, "SLUG", None), "TABLE_COLS") -                if tb_key in settings.TABLE_COLS: -                    table_cols = settings.TABLE_COLS[tb_key] -                else: -                    table_cols = model.TABLE_COLS -        if callable(table_cols): -            table_cols = table_cols() -        table_cols = list(table_cols) -        if data_type == "json-map": -            table_cols = []  # only pk for map -        elif data_type == "json-stats": +        if data_type == "json-stats":              stats_modality_1 = request_items.get("stats_modality_1", None)              stats_modality_2 = request_items.get("stats_modality_2", None)              if (  | 
