Use new 'ContainerAdminView' base class
authorThierry Florac <thierry.florac@onf.fr>
Tue, 19 Sep 2017 11:11:12 +0200
changeset 169 483b0f16e9a6
parent 168 0d80c3c49bab
child 170 26aefef3d0aa
Use new 'ContainerAdminView' base class
src/pyams_content/component/paragraph/zmi/container.py
src/pyams_content/component/paragraph/zmi/templates/container.pt
--- a/src/pyams_content/component/paragraph/zmi/container.py	Tue Sep 19 11:10:46 2017 +0200
+++ b/src/pyams_content/component/paragraph/zmi/container.py	Tue Sep 19 11:11:12 2017 +0200
@@ -9,7 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_content.component.association.zmi import AssociationsContainerView
 
 __docformat__ = 'restructuredtext'
 
@@ -35,6 +34,7 @@
 from zope.contentprovider.interfaces import IContentProvider
 
 # import packages
+from pyams_content.component.association.zmi import AssociationsContainerView
 from pyams_content.shared.common.zmi import WfModifiedContentColumnMixin
 from pyams_form.security import ProtectedFormObjectMixin
 from pyams_pagelet.pagelet import pagelet_config
@@ -48,7 +48,7 @@
 from pyramid.exceptions import NotFound
 from pyramid.view import view_config
 from pyams_viewlet.viewlet import viewlet_config, Viewlet
-from pyams_zmi.view import AdminView
+from pyams_zmi.view import AdminView, ContainerAdminView
 from pyramid.decorator import reify
 from z3c.table.column import GetAttrColumn
 from zope.interface import implementer
@@ -70,24 +70,6 @@
 # Paragraphs container view
 #
 
-@pagelet_config(name='paragraphs.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
-                permission=VIEW_SYSTEM_PERMISSION)
-@template_config(template='templates/container.pt', layer=IPyAMSLayer)
-@implementer(IInnerPage)
-class ParagraphContainerView(AdminView):
-    """Paragraphs container view"""
-
-    title = _("Paragraphs list")
-
-    def __init__(self, context, request):
-        super(ParagraphContainerView, self).__init__(context, request)
-        self.table = ParagraphContainerTable(context, request, self)
-
-    def update(self):
-        super(ParagraphContainerView, self).update()
-        self.table.update()
-
-
 class ParagraphContainerTable(ProtectedFormObjectMixin, BaseTable):
     """Paragraphs container table"""
 
@@ -95,10 +77,6 @@
     hide_header = True
     sortOn = None
 
-    def __init__(self, context, request, view):
-        super(ParagraphContainerTable, self).__init__(context, request)
-        self.view = view
-
     @property
     def cssClasses(self):
         classes = ['table', 'table-bordered', 'table-striped', 'table-hover', 'table-tight']
@@ -179,6 +157,15 @@
         return self.request.localizer.translate(item.icon_hint)
 
 
+@pagelet_config(name='paragraphs.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+class ParagraphContainerView(ContainerAdminView):
+    """Paragraphs container view"""
+
+    title = _("Paragraphs list")
+    table_class = ParagraphContainerTable
+
+
 @adapter_config(context=ParagraphContainerShowHideColumn, provides=IFormSecurityContext)
 def ShowHideColumnSecurityContextFactory(column):
     """Show/hide column security context factory"""
--- a/src/pyams_content/component/paragraph/zmi/templates/container.pt	Tue Sep 19 11:10:46 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-<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>