Use new 'ContainerAdminView' base class
authorThierry Florac <thierry.florac@onf.fr>
Tue, 19 Sep 2017 11:08:52 +0200
changeset 165 2912fbd45f62
parent 164 826753ab9e52
child 166 bdacf9434df6
Use new 'ContainerAdminView' base class
src/pyams_content/component/association/zmi/__init__.py
src/pyams_content/component/association/zmi/templates/associations-view.pt
--- a/src/pyams_content/component/association/zmi/__init__.py	Wed Sep 13 15:58:14 2017 +0200
+++ b/src/pyams_content/component/association/zmi/__init__.py	Tue Sep 19 11:08:52 2017 +0200
@@ -21,7 +21,6 @@
 from pyams_content.component.association.zmi.interfaces import IAssociationsParentForm, IAssociationsView
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
 from pyams_form.interfaces.form import IInnerSubForm
-from pyams_skin.interfaces import IInnerPage
 from pyams_skin.layer import IPyAMSLayer
 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
 from pyams_zmi.interfaces.menu import IPropertiesMenu
@@ -39,7 +38,7 @@
 from pyams_utils.url import absolute_url
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import InnerAdminDisplayForm
-from pyams_zmi.view import AdminView
+from pyams_zmi.view import ContainerAdminView
 from pyramid.decorator import reify
 from pyramid.exceptions import NotFound
 from pyramid.view import view_config
@@ -58,7 +57,7 @@
     """Association item add form, JSON renderer"""
 
     def get_ajax_output(self, changes):
-        associations_table = AssociationsTable(self.context, self.request, None)
+        associations_table = AssociationsTable(self.context, self.request)
         associations_table.update()
         return {'status': 'success',
                 'message': self.request.localizer.translate(_("Association was correctly added.")),
@@ -72,7 +71,7 @@
 
     def get_associations_table(self):
         target = get_parent(self.context, IAssociationTarget)
-        associations_table = AssociationsTable(target, self.request, None)
+        associations_table = AssociationsTable(target, self.request)
         associations_table.update()
         return {'status': 'success',
                 'message': self.request.localizer.translate(self.successMessage),
@@ -95,43 +94,6 @@
     url = '#associations.html'
 
 
-@pagelet_config(name='associations.html', context=IAssociationTarget, layer=IPyAMSLayer,
-                permission=VIEW_SYSTEM_PERMISSION)
-@template_config(template='templates/associations-view.pt', layer=IPyAMSLayer)
-@implementer(IInnerPage, IAssociationsView)
-class AssociationsContainerView(AdminView, Pagelet):
-    """Associations container view"""
-
-    title = _("Associations list")
-
-    def __init__(self, context, request):
-        super(AssociationsContainerView, self).__init__(context, request)
-        self.table = AssociationsTable(context, request, self)
-
-    def update(self):
-        super(AssociationsContainerView, self).update()
-        self.table.update()
-
-
-@adapter_config(name='associations', context=(IAssociationTarget, IPyAMSLayer, IAssociationsParentForm),
-                provides=IInnerSubForm)
-@template_config(template='templates/associations.pt', layer=IPyAMSLayer)
-@implementer(IAssociationsView)
-class AssociationsView(InnerAdminDisplayForm):
-    """Associations view"""
-
-    fields = field.Fields(Interface)
-    weight = 90
-
-    def __init__(self, context, request, view):
-        super(AssociationsView, self).__init__(context, request, view)
-        self.table = AssociationsTable(context, request, self)
-
-    def update(self):
-        super(AssociationsView, self).update()
-        self.table.update()
-
-
 class AssociationsTable(ProtectedFormObjectMixin, BaseTable):
     """Associations view inner table"""
 
@@ -142,10 +104,6 @@
     hide_header = True
     sortOn = None
 
-    def __init__(self, context, request, view):
-        super(AssociationsTable, self).__init__(context, request)
-        self.view = view
-
     @property
     def cssClasses(self):
         classes = ['table', 'table-bordered', 'table-striped', 'table-hover', 'table-tight']
@@ -297,3 +255,33 @@
 @adapter_config(name='trash', context=(IAssociationTarget, IPyAMSLayer, AssociationsTable), provides=IColumn)
 class AssociationsTableTrashColumn(ProtectedFormObjectMixin, TrashColumn):
     """Associations table trash column"""
+
+
+@pagelet_config(name='associations.html', context=IAssociationTarget, layer=IPyAMSLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+@implementer(IAssociationsView)
+class AssociationsContainerView(ContainerAdminView, Pagelet):
+    """Associations container view"""
+
+    title = _("Associations list")
+    table_class = AssociationsTable
+
+
+@adapter_config(name='associations', context=(IAssociationTarget, IPyAMSLayer, IAssociationsParentForm),
+                provides=IInnerSubForm)
+@template_config(template='templates/associations.pt', layer=IPyAMSLayer)
+@implementer(IAssociationsView)
+class AssociationsView(InnerAdminDisplayForm):
+    """Associations view"""
+
+    fields = field.Fields(Interface)
+    weight = 90
+
+    def __init__(self, context, request, view):
+        super(AssociationsView, self).__init__(context, request, view)
+        self.table = AssociationsTable(context, request)
+        self.table.view = self
+
+    def update(self):
+        super(AssociationsView, self).update()
+        self.table.update()
--- a/src/pyams_content/component/association/zmi/templates/associations-view.pt	Wed Sep 13 15:58:14 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>