From 05b9acf3048eaefa89e57011968c220fd8c2c2a7 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 1 Oct 2018 18:50:02 +0200 Subject: Manage column customization on custom app --- ishtar_common/widgets.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'ishtar_common/widgets.py') diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 405b5d69e..fc8926364 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -945,9 +945,19 @@ class DataTable(Select2Media, forms.RadioSelect): def get_cols(self, python=False): jq_col_names, extra_cols = [], [] col_labels = {} + slug = getattr(self.associated_model, 'SLUG', None) if hasattr(self.associated_model, 'COL_LABELS'): col_labels = self.associated_model.COL_LABELS - for col_names in getattr(self.associated_model, self.table_cols): + if slug in settings.TABLE_COLS: + col_labels.update(settings.TABLE_COLS[slug]) + + tb_key = (slug, self.table_cols) + if tb_key in settings.TABLE_COLS: + table_cols = settings.TABLE_COLS[tb_key] + else: + table_cols = getattr(self.associated_model, self.table_cols) + + for col_names in table_cols: field_verbose_names = [] field_verbose_name, field_name = "", "" if type(col_names) not in (list, tuple): @@ -978,7 +988,10 @@ class DataTable(Select2Media, forms.RadioSelect): if not field_name: field_name = "__".join(col_names) if field_name in col_labels: - jq_col_names.append(unicode(col_labels[field_name])) + lbl = col_labels[field_name] + if callable(lbl): + lbl = lbl() + jq_col_names.append(unicode(lbl)) elif col_names and col_names[0] in col_labels: jq_col_names.append(unicode(col_labels[col_names[0]])) else: -- cgit v1.2.3