Added base class for simple table viewlet
authorThierry Florac <thierry.florac@onf.fr>
Fri, 26 Jan 2018 15:50:22 +0100
changeset 261 619c20502448
parent 260 a013bb277b99
child 262 62ea7078d7c9
Added base class for simple table viewlet
src/pyams_skin/table.py
src/pyams_skin/templates/table-viewlet.pt
--- a/src/pyams_skin/table.py	Fri Jan 26 15:49:50 2018 +0100
+++ b/src/pyams_skin/table.py	Fri Jan 26 15:50:22 2018 +0100
@@ -12,6 +12,7 @@
 
 __docformat__ = 'restructuredtext'
 
+
 # import standard library
 
 # import interfaces
@@ -27,6 +28,7 @@
 from pyams_template.template import get_view_template, template_config
 from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config
 from pyams_utils.url import absolute_url
+from pyams_viewlet.viewlet import Viewlet
 from pyramid.url import resource_url
 from z3c.table.column import Column, GetAttrColumn
 from z3c.table.table import Table
@@ -323,3 +325,18 @@
     icon_hint = _("Delete object")
     permission = MANAGE_PERMISSION
     weight = 9999
+
+
+@template_config(template='templates/table-viewlet.pt', layer=IPyAMSLayer)
+class TableViewlet(Viewlet):
+    """Table viewlet"""
+
+    table_class = None
+
+    def __init__(self, context, request, view, manager):
+        super(TableViewlet, self).__init__(context, request, view, manager)
+        self.table = self.table_class(context, request)
+
+    def update(self):
+        super(TableViewlet, self).update()
+        self.table.update()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_skin/templates/table-viewlet.pt	Fri Jan 26 15:50:22 2018 +0100
@@ -0,0 +1,3 @@
+<div class="no-widget-toolbar">
+	<tal:var replace="structure view.table.render()" />
+</div>