diff options
Diffstat (limited to 'ishtar_common/views.py')
| -rw-r--r-- | ishtar_common/views.py | 38 | 
1 files changed, 28 insertions, 10 deletions
| diff --git a/ishtar_common/views.py b/ishtar_common/views.py index a4ad130be..94d754938 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -880,15 +880,23 @@ def get_item(model, func_name, default_name, extra_request_keys=[],              else:                  table_cols = model.TABLE_COLS +        query_table_cols = [] +        for cols in table_cols: +            if type(cols) not in (list, tuple): +                cols = [cols] +            for col in cols: +                query_table_cols += col.split('|') +          # contextual (full, simple, etc.) col          contxt = full and 'full' or 'simple'          if hasattr(model, 'CONTEXTUAL_TABLE_COLS') and \                  contxt in model.CONTEXTUAL_TABLE_COLS:              for idx, col in enumerate(table_cols):                  if col in model.CONTEXTUAL_TABLE_COLS[contxt]: -                    table_cols[idx] = model.CONTEXTUAL_TABLE_COLS[contxt][col] +                    query_table_cols[idx] = \ +                        model.CONTEXTUAL_TABLE_COLS[contxt][col]          if full == 'shortcut': -            table_cols = ['cached_label'] +            query_table_cols = ['cached_label']          # manage sort tables          manual_sort_key = None @@ -912,7 +920,7 @@ def get_item(model, func_name, default_name, extra_request_keys=[],                  orders.append(sign + k)              items = items.order_by(*orders)          elif q: -            for ke in table_cols: +            for ke in query_table_cols:                  if type(ke) in (list, tuple):                      ke = ke[0]                  if ke.endswith(q): @@ -957,7 +965,7 @@ def get_item(model, func_name, default_name, extra_request_keys=[],                  continue              c_ids.append(item.pk)              data = [item.pk] -            for keys in table_cols: +            for keys in query_table_cols:                  if type(keys) not in (list, tuple):                      keys = [keys]                  my_vals = [] @@ -1022,10 +1030,10 @@ def get_item(model, func_name, default_name, extra_request_keys=[],          if manual_sort_key:              # +1 because the id is added as a first col              idx_col = None -            if manual_sort_key in table_cols: -                idx_col = table_cols.index(manual_sort_key) + 1 +            if manual_sort_key in query_table_cols: +                idx_col = query_table_cols.index(manual_sort_key) + 1              else: -                for idx, col in enumerate(table_cols): +                for idx, col in enumerate(query_table_cols):                      if type(col) in (list, tuple) and \                              manual_sort_key in col:                          idx_col = idx + 1 @@ -1114,8 +1122,18 @@ def get_item(model, func_name, default_name, extra_request_keys=[],                          unicode(field.verbose_name).encode(ENCODING))              writer.writerow(col_names)              for data in datas: -                writer.writerow([val.encode(ENCODING, errors='replace') -                                 for val in data[1:]]) +                row, delta = [], 0 +                # regroup cols with join "|" +                for idx, col_name in enumerate(table_cols): +                    val = data[1:][idx + delta].encode( +                        ENCODING, errors='replace') +                    if "|" in col_name[0]: +                        for delta_idx in range(len(col_name[0].split('|')) - 1): +                            delta += 1 +                            val += data[1:][idx + delta].encode( +                                ENCODING, errors='replace') +                    row.append(val) +                writer.writerow(row)              return response          return HttpResponse('{}', mimetype='text/plain') @@ -1135,7 +1153,7 @@ def get_by_importer(request, slug, data_type='json', full=False,      for formater in imp.LINE_FORMAT:          if not formater:              continue -        cols.append(formater.field_name) +        cols.append(formater.export_field_name)      obj_name = imp.OBJECT_CLS.__name__.lower()      return get_item(          imp.OBJECT_CLS, 'get_' + obj_name, obj_name, own_table_cols=cols | 
