Updated ZMI
authorThierry Florac <thierry.florac@onf.fr>
Thu, 14 Jun 2018 10:40:46 +0200
changeset 681 bb371b8a67e4
parent 680 508a73cab999
child 682 d093aba47072
child 697 16c83f565a48
Updated ZMI
src/pyams_content/component/keynumber/__init__.py
src/pyams_content/component/keynumber/zmi/__init__.py
--- a/src/pyams_content/component/keynumber/__init__.py	Thu Jun 14 10:40:08 2018 +0200
+++ b/src/pyams_content/component/keynumber/__init__.py	Thu Jun 14 10:40:46 2018 +0200
@@ -9,27 +9,7 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyramid.events import subscriber
-from zope.container.contained import Contained
-from zope.container.ordered import OrderedContainer
-from zope.lifecycleevent import ObjectModifiedEvent
-from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent
-from zope.location.interfaces import ISublocations
-from zope.location.location import locate
-from zope.schema.fieldproperty import FieldProperty
-from zope.traversing.interfaces import ITraversable
 
-from pyams_catalog.utils import index_object
-from pyams_content.component.keynumber.interfaces import IKeyNumber, IKeyNumberContainerTarget, IKeyNumberContainer, \
-    KEYNUMBER_CONTAINER_KEY
-from pyams_content.features.checker import BaseContentChecker
-from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
-from pyams_form.interfaces.form import IFormContextPermissionChecker
-from pyams_i18n.interfaces import II18n, II18nManager, INegotiator
-from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
-from pyams_utils.registry import get_current_registry, get_utility
-from pyams_utils.request import check_request
-from pyams_utils.traversing import get_parent
 
 __docformat__ = 'restructuredtext'
 
@@ -37,10 +17,30 @@
 # import standard library
 
 # import interfaces
+from pyams_content.component.keynumber.interfaces import IKeyNumber, IKeyNumberContainerTarget, IKeyNumberContainer, \
+    KEYNUMBER_CONTAINER_KEY
+from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
+from pyams_form.interfaces.form import IFormContextPermissionChecker
+from pyams_i18n.interfaces import II18n, II18nManager, INegotiator
+from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent
+from zope.location.interfaces import ISublocations
+from zope.traversing.interfaces import ITraversable
 
 # import packages
+from pyams_catalog.utils import index_object
+from pyams_content.features.checker import BaseContentChecker
+from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
+from pyams_utils.registry import get_current_registry, get_utility
+from pyams_utils.request import check_request
+from pyams_utils.traversing import get_parent
 from persistent import Persistent
+from pyramid.events import subscriber
+from zope.container.contained import Contained
+from zope.container.ordered import OrderedContainer
 from zope.interface import implementer
+from zope.lifecycleevent import ObjectModifiedEvent
+from zope.location.location import locate
+from zope.schema.fieldproperty import FieldProperty
 
 from pyams_content import _
 
--- a/src/pyams_content/component/keynumber/zmi/__init__.py	Thu Jun 14 10:40:08 2018 +0200
+++ b/src/pyams_content/component/keynumber/zmi/__init__.py	Thu Jun 14 10:40:46 2018 +0200
@@ -9,23 +9,29 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyramid.decorator import reify
-from pyramid.view import view_config
-from z3c.table.column import GetAttrColumn
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+import json
+
+# import interfaces
+from pyams_content.component.keynumber.interfaces import IKeyNumberContainer, IKeyNumberContainerTarget, IKeyNumber
+from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
+from pyams_form.interfaces.form import IInnerSubForm
+from pyams_skin.interfaces.viewlet import IWidgetTitleViewletManager
+from pyams_skin.layer import IPyAMSLayer
 from z3c.table.interfaces import IValues, IColumn
 
-from pyams_content.component.keynumber import IKeyNumberContainer, IKeyNumberContainerTarget, IKeyNumber, KeyNumber
-from pyams_content.component.paragraph import IParagraphContainerTarget
-from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
+# import packages
+from pyams_content.component.keynumber import KeyNumber
 from pyams_form.form import ajax_config, AJAXAddForm
-from pyams_form.interfaces.form import IInnerSubForm
 from pyams_form.security import ProtectedFormObjectMixin
 from pyams_i18n.column import I18nAttrColumn
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.container import switch_element_visibility
 from pyams_skin.event import get_json_table_row_refresh_event, get_json_switched_table_refresh_event
-from pyams_skin.interfaces.viewlet import IWidgetTitleViewletManager
-from pyams_skin.layer import IPyAMSLayer
 from pyams_skin.table import BaseTable, SorterColumn, VisibilitySwitcherColumn, I18nColumn, TrashColumn
 from pyams_skin.viewlet.toolbar import ToolbarAction
 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
@@ -34,22 +40,19 @@
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogAddForm, AdminDialogEditForm
 from pyams_zmi.zmi.table import InnerTableView
-
-__docformat__ = 'restructuredtext'
-
-
-# import standard library
-import json
-
-# import interfaces
-
-# import packages
+from pyramid.decorator import reify
+from pyramid.view import view_config
 from z3c.form import field
+from z3c.table.column import GetAttrColumn
 from zope.interface import implementer, Interface
 
 from pyams_content import _
 
 
+#
+# Views marker interfaces
+#
+
 class IKeyNumbersView(Interface):
     """Key numbers view marker interface"""
 
@@ -68,9 +71,14 @@
     prefix = 'keynumbers'
 
     hide_header = True
+    hide_body_toolbar = True
     sortOn = None
 
-    @property
+    @classmethod
+    def get_context(cls, context):
+        return IKeyNumberContainer(context)
+
+    @reify
     def cssClasses(self):
         classes = ['table', 'table-bordered', 'table-striped', 'table-hover', 'table-tight']
         permission = self.permission
@@ -78,15 +86,16 @@
             classes.append('table-dnd')
         return {'table': ' '.join(classes)}
 
-    @property
+    @reify
     def data_attributes(self):
+        container = IKeyNumberContainer(self.context)
         attributes = super(KeyNumbersTable, self).data_attributes
-        attributes['table'] = {
-            'data-ams-location': absolute_url(IKeyNumberContainer(self.context), self.request),
+        attributes.setdefault('table', {}).update({
+            'data-ams-location': absolute_url(container, self.request),
             'data-ams-tablednd-drag-handle': 'td.sorter',
             'data-ams-tablednd-drop-target': 'set-keynumbers-order.json',
             'data-ams-visibility-switcher': 'switch-keynumber-visibility.json'
-        }
+        })
         return attributes
 
     @reify
@@ -94,7 +103,7 @@
         return list(super(KeyNumbersTable, self).values)
 
 
-@adapter_config(context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IValues)
+@adapter_config(context=(IKeyNumberContainer, IPyAMSLayer, KeyNumbersTable), provides=IValues)
 class KeyNumbersTableValuesAdapter(ContextRequestViewAdapter):
     """Key numbers table values adapter"""
 
@@ -103,7 +112,7 @@
         return IKeyNumberContainer(self.context).values()
 
 
-@adapter_config(name='sorter', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
+@adapter_config(name='sorter', context=(IKeyNumberContainer, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
 class KeyNumbersTableSorterColumn(ProtectedFormObjectMixin, SorterColumn):
     """Key numbers table sorter column"""
 
@@ -117,7 +126,7 @@
     return {'status': 'success'}
 
 
-@adapter_config(name='show-hide', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable),
+@adapter_config(name='show-hide', context=(IKeyNumberContainer, IPyAMSLayer, KeyNumbersTable),
                 provides=IColumn)
 class KeyNumbersTableShowHideColumn(ProtectedFormObjectMixin, VisibilitySwitcherColumn):
     """Key numbers container visibility switcher column"""
@@ -130,7 +139,7 @@
     return switch_element_visibility(request, IKeyNumberContainer)
 
 
-@adapter_config(name='label', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
+@adapter_config(name='label', context=(IKeyNumberContainer, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
 class KeyNumbersTableLabelColumn(I18nColumn, I18nAttrColumn):
     """Key numbers table label column"""
 
@@ -142,7 +151,7 @@
         return super(KeyNumbersTableLabelColumn, self).getValue(obj) or '--'
 
 
-@adapter_config(name='name', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
+@adapter_config(name='name', context=(IKeyNumberContainer, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
 class KeyNumbersTableNameColumn(I18nColumn, GetAttrColumn):
     """Key numbers table number column"""
 
@@ -151,7 +160,7 @@
     weight = 20
 
 
-@adapter_config(name='unit', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
+@adapter_config(name='unit', context=(IKeyNumberContainer, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
 class KeyNumbersTableUnitColumn(I18nColumn, I18nAttrColumn):
     """Key numbers table unit column"""
 
@@ -163,7 +172,7 @@
         return super(KeyNumbersTableUnitColumn, self).getValue(obj) or '--'
 
 
-@adapter_config(name='text', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
+@adapter_config(name='text', context=(IKeyNumberContainer, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
 class KeyNumbersTableTextColumn(I18nColumn, I18nAttrColumn):
     """Key numbers table text column"""
 
@@ -175,7 +184,7 @@
         return super(KeyNumbersTableTextColumn, self).getValue(obj) or '--'
 
 
-@adapter_config(name='trash', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
+@adapter_config(name='trash', context=(IKeyNumberContainer, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
 class KeyNumbersTableTrashColumn(ProtectedFormObjectMixin, TrashColumn):
     """Key numbers table trash column"""
 
@@ -191,6 +200,10 @@
     table_class = KeyNumbersTable
     weight = 110
 
+    @property
+    def actions_context(self):  # define context for internal actions
+        return IKeyNumberContainer(self.context)
+
 
 #
 # Key numbers forms
@@ -207,9 +220,9 @@
     modal_target = True
 
 
-@pagelet_config(name='add-keynumber.html', context=IKeyNumberContainerTarget, layer=IPyAMSLayer,
+@pagelet_config(name='add-keynumber.html', context=IKeyNumberContainer, layer=IPyAMSLayer,
                 permission=MANAGE_CONTENT_PERMISSION)
-@ajax_config(name='add-keynumber.json', context=IParagraphContainerTarget, layer=IPyAMSLayer,
+@ajax_config(name='add-keynumber.json', context=IKeyNumberContainer, layer=IPyAMSLayer,
              base=AJAXAddForm)
 class KeyNumberAddForm(AdminDialogAddForm):
     """Key number add form"""
@@ -230,7 +243,9 @@
         return {
             'status': 'success',
             'message': self.request.localizer.translate(_("Key number was correctly added")),
-            'events': [get_json_switched_table_refresh_event(self.context, self.request, KeyNumbersTable), ]
+            'events': [
+                get_json_switched_table_refresh_event(self.context, self.request, KeyNumbersTable)
+            ]
         }