summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-10-01 18:50:02 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-10-01 18:50:02 +0200
commit4392454570b36c1e0bf9c0d4a365efb99c8b8342 (patch)
treefadcd9d09ac5fa97db0a28ccabdbb2ecbffaa831
parent0c29c68c09bf45306c02658a31e2f99581169cb1 (diff)
downloadIshtar-4392454570b36c1e0bf9c0d4a365efb99c8b8342.tar.bz2
Ishtar-4392454570b36c1e0bf9c0d4a365efb99c8b8342.zip
Manage column customization on custom app
-rw-r--r--archaeological_finds/models_finds.py6
-rw-r--r--example_project/settings.py9
-rw-r--r--ishtar_common/views_item.py6
-rw-r--r--ishtar_common/widgets.py17
4 files changed, 34 insertions, 4 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index ea111f0d2..51da262b8 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -38,7 +38,7 @@ from ishtar_common.alternative_configs import ALTERNATE_CONFIGS
from ishtar_common.models import Document, GeneralType, \
HierarchicalType, BaseHistorizedItem, ShortMenuItem, LightHistorizedItem, \
HistoricalRecords, OwnPerms, Person, Basket, post_save_cache, \
- ValueGetter, get_current_profile
+ ValueGetter, get_current_profile, IshtarSiteProfile
from archaeological_operations.models import AdministrativeAct, Operation
from archaeological_context_records.models import ContextRecord, Dating
@@ -638,6 +638,8 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,
'base_finds__context_record__operation__common_name': _(
u"Operation (name)"
),
+ 'base_finds__context_record__archaeological_site__name':
+ IshtarSiteProfile.get_default_site_label,
'base_finds__context_record__parcel': _(u"Parcel"),
'base_finds__batch':_(u"Batch"),
'base_finds__comment': _(u"Base find - Comment"),
@@ -699,6 +701,8 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,
'base_finds__context_record__operation__code_patriarche',
'base_finds__context_record__town__areas':
'base_finds__context_record__town__areas__pk',
+ 'base_finds__context_record__archaeological_site__name':
+ 'base_finds__context_record__archaeological_site__name',
'datings__period': 'datings__period__pk',
'base_finds__find__description':
'base_finds__find__description__icontains',
diff --git a/example_project/settings.py b/example_project/settings.py
index db9a3ee64..a27046f5f 100644
--- a/example_project/settings.py
+++ b/example_project/settings.py
@@ -4,6 +4,7 @@
import os
import sys
+from importlib import import_module
DEBUG = False
DEBUG_TOOLBAR = False
@@ -265,8 +266,16 @@ try:
except ImportError, e:
print('Unable to load local_settings.py:', e)
+TABLE_COLS = {} # allow to overload table col settings on extra module
+COL_LABELS = {}
+
if MAIN_APP:
INSTALLED_APPS.insert(INSTALLED_APPS.index("ishtar_common"), MAIN_APP)
+ extra_module = import_module(MAIN_APP + '.extra_settings')
+ if hasattr(extra_module, 'TABLE_COLS'):
+ TABLE_COLS = extra_module.TABLE_COLS
+ if hasattr(extra_module, 'COL_LABELS'):
+ TABLE_COLS = extra_module.COL_LABELS
TESTING = sys.argv[1:2] == ['test']
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index a6bf7e190..3fa49bd07 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -1087,7 +1087,11 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
if hasattr(model, 'EXTRA_FULL_FIELDS'):
table_cols += model.EXTRA_FULL_FIELDS
else:
- table_cols = model.TABLE_COLS
+ 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
query_table_cols = []
for cols in table_cols:
if type(cols) not in (list, tuple):
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: