--- a/src/pyams_skin/table.py Wed Nov 15 17:04:37 2017 +0100
+++ b/src/pyams_skin/table.py Sun Nov 26 10:08:22 2017 +0100
@@ -66,12 +66,19 @@
@property
def data_attributes(self):
- return {'tr': {'id': lambda x, col: '{0}::{1}'.format(self.id, getattr(x, '__name__', '')),
- 'data-ams-element-name': lambda x, col: getattr(x, '__name__', None),
- 'data-ams-url': lambda x, col: getattr(get_element_editor(self, x), 'url', None),
- 'data-toggle': lambda x, col: 'modal' if getattr(get_element_editor(self, x), 'modal_target',
- None) else None},
- 'th': {'data-ams-datatable-stype': self.get_column_type}}
+ return {
+ 'tr': {
+ 'id': lambda x, col: '{0}::{1}'.format(self.id, getattr(x, '__name__', '')),
+ 'data-ams-element-name': lambda x, col: getattr(x, '__name__', None),
+ 'data-ams-url': lambda x, col: getattr(get_element_editor(self, x), 'url', None),
+ 'data-toggle': lambda x, col: 'modal' if getattr(get_element_editor(self, x), 'modal_target',
+ None) else None
+ },
+ 'th': {
+ 'data-ams-column-name': lambda x, col: x.__name__,
+ 'data-ams-datatable-stype': self.get_column_type
+ }
+ }
batchSize = 10000
startBatchingAt = 10000
@@ -161,6 +168,20 @@
return self.defaultValue
+def get_object_name(context, request, view=None):
+ """Get required object name"""
+ registry = request.registry
+ adapter = None
+ if view is not None:
+ adapter = registry.queryMultiAdapter((context, request, view), ITableElementName)
+ if adapter is None:
+ adapter = registry.queryMultiAdapter((context, request), ITableElementName)
+ if adapter is None:
+ adapter = registry.queryAdapter(context, ITableElementName)
+ if adapter is not None:
+ return adapter.name
+
+
@adapter_config(name='name', context=(Interface, IPyAMSLayer, BaseTable), provides=IColumn)
class NameColumn(I18nColumn, GetAttrColumn):
"""Container name column"""
@@ -172,16 +193,10 @@
dt_sort_type = 'string'
def getValue(self, obj):
- registry = self.request.registry
- adapter = registry.queryMultiAdapter((obj, self.request, self.table), ITableElementName)
- if adapter is None:
- adapter = registry.queryMultiAdapter((obj, self.request), ITableElementName)
- if adapter is None:
- adapter = registry.queryAdapter(obj, ITableElementName)
- if adapter is not None:
- return adapter.name
- else:
- return super(NameColumn, self).getValue(obj)
+ name = get_object_name(obj, self.request, self.table)
+ if name is None:
+ name = super(NameColumn, self).getValue(obj)
+ return name
class ActionColumn(Column):