Added base class for admin container view
authorThierry Florac <thierry.florac@onf.fr>
Tue, 19 Sep 2017 11:25:10 +0200
changeset 35 a9a665e34874
parent 34 23b9da6acdd8
child 36 9a3976b90680
Added base class for admin container view
src/pyams_zmi/templates/container.pt
src/pyams_zmi/view.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_zmi/templates/container.pt	Tue Sep 19 11:25:10 2017 +0200
@@ -0,0 +1,13 @@
+<div class="ams-widget">
+	<header>
+		<span tal:condition="view.widget_icon_class | nothing"
+			  class="widget-icon"><i tal:attributes="class view.widget_icon_class"></i>
+		</span>
+		<h2 tal:content="view.title"></h2>
+		<tal:var content="structure provider:pyams.widget_title" />
+		<tal:var content="structure provider:pyams.toolbar" />
+	</header>
+	<div class="widget-body no-widget-toolbar">
+		<tal:var content="structure view.table.render()" />
+	</div>
+</div>
--- a/src/pyams_zmi/view.py	Mon Sep 11 15:10:09 2017 +0200
+++ b/src/pyams_zmi/view.py	Tue Sep 19 11:25:10 2017 +0200
@@ -23,7 +23,9 @@
 
 # import packages
 from pyams_skin.skin import apply_skin
+from pyams_template.template import template_config
 from pyramid.events import subscriber
+from z3c.table.table import Table
 from zope.interface import implementer
 
 
@@ -39,6 +41,22 @@
     """Inner admin view"""
 
 
+@template_config(template='templates/container.pt', layer=IAdminLayer)
+class ContainerAdminView(InnerAdminView):
+    """Container admin view"""
+
+    table_class = Table
+
+    def __init__(self, context, request):
+        super(ContainerAdminView, self).__init__(context, request)
+        self.table = self.table_class(context, request)
+        self.table.view = self
+
+    def update(self):
+        super(ContainerAdminView, self).update()
+        self.table.update()
+
+
 @subscriber(IPageletCreatedEvent, context_selector=IAdminView)
 def handle_admin_view(event):
     """Set skin for admin views"""