Added 'table' module to handle base table elements
authorThierry Florac <tflorac@ulthar.net>
Sat, 21 Feb 2015 13:54:19 +0100
changeset 2 a0a4774f0ce9
parent 1 7fc1c60c01eb
child 3 a93a571fafca
Added 'table' module to handle base table elements
src/pyams_skin/table.py
--- a/src/pyams_skin/table.py	Sat Feb 21 13:52:31 2015 +0100
+++ b/src/pyams_skin/table.py	Sat Feb 21 13:54:19 2015 +0100
@@ -56,7 +56,7 @@
 class BaseTable(Table):
     """Custom table"""
 
-    id = _("TableID")
+    id = "TableID"
     title = _("Container elements")
 
     cssClasses = {'table': 'table table-bordered table-striped table-hover table-tight datatable'}
@@ -119,30 +119,47 @@
                                      .replace('<td', '<td %s' % self.get_data_attributes('td', item, column))
 
 
+class I18nColumn(object):
+    """Column with I18n header column"""
+
+    _header = None
+    request = None
+
+    @property
+    def header(self):
+        if not self._header:
+            return ''
+        return self.request.localizer.translate(self._header)
+
+
 @adapter_config(name='name', context=(Interface, IPyAMSLayer, BaseTable), provides=IColumn)
-class NameColumn(GetAttrColumn):
-    """Container column"""
+class NameColumn(I18nColumn, GetAttrColumn):
+    """Container name column"""
 
-    header = _("Name")
+    _header = _("Name")
     attrName = '__name__'
+    weight = 10
 
 
 class ActionColumn(Column):
     """Base action icon column"""
 
     header = ''
-    icon_class = 'fa fa-fw fa-search'
-    icon_hint = _("Search")
+    icon_class = 'fa fa-fw fa-edit'
+    icon_hint = _("Properties")
     cssClasses = {'th': 'action',
                   'td': 'action'}
     url = "#"
     target = '#content'
     modal_target = False
+    permission = None
 
     def renderCell(self, item):
+        if self.permission and not self.request.has_permission(self.permission):
+            return ''
         translate = self.request.localizer.translate
         return '''<a class="hint" title="{title}" href="{url}"
-                     data-ams-target="{target}" {modal} data-ams-hint-gravity="se">
+                     data-ams-target="{target}" {modal} data-ams-hint-gravity="e">
             <i class="{icon_class}"></i>
         </a>'''.format(title=translate(self.icon_hint),
                        url=self.get_url(item),