Moved "key numbers" feature to dedicated component
authorThierry Florac <thierry.florac@onf.fr>
Wed, 13 Jun 2018 17:31:17 +0200
changeset 671 b6ca6378a8f8
parent 670 fecfd4969c4f
child 672 adff375e9deb
Moved "key numbers" feature to dedicated component
src/pyams_content/component/keynumber/__init__.py
src/pyams_content/component/keynumber/interfaces/__init__.py
src/pyams_content/component/keynumber/zmi/__init__.py
src/pyams_content/component/paragraph/interfaces/keynumber.py
src/pyams_content/component/paragraph/keynumber.py
src/pyams_content/component/paragraph/zmi/keynumber.py
src/pyams_content/generations/__init__.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/keynumber/__init__.py	Wed Jun 13 17:31:17 2018 +0200
@@ -0,0 +1,195 @@
+#
+# Copyright (c) 2008-2018 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# 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'
+
+
+# import standard library
+
+# import interfaces
+
+# import packages
+from persistent import Persistent
+from zope.interface import implementer
+
+from pyams_content import _
+
+
+#
+# Key number class and adapters
+#
+
+@implementer(IKeyNumber)
+class KeyNumber(Persistent, Contained):
+    """Key number persistent class"""
+
+    visible = FieldProperty(IKeyNumber['visible'])
+    label = FieldProperty(IKeyNumber['label'])
+    number = FieldProperty(IKeyNumber['number'])
+    unit = FieldProperty(IKeyNumber['unit'])
+    text = FieldProperty(IKeyNumber['text'])
+
+
+@adapter_config(context=IKeyNumber, provides=IFormContextPermissionChecker)
+class KeyNumberPermissionChecker(ContextAdapter):
+    """Key number permission checker"""
+
+    @property
+    def edit_permission(self):
+        content = get_parent(self.context, IKeyNumberContainerTarget)
+        return IFormContextPermissionChecker(content).edit_permission
+
+
+@subscriber(IObjectAddedEvent, context_selector=IKeyNumber)
+def handle_added_keynumber(event):
+    """Handle added key number"""
+    content = get_parent(event.object, IKeyNumberContainerTarget)
+    if content is not None:
+        get_current_registry().notify(ObjectModifiedEvent(content))
+
+
+@subscriber(IObjectModifiedEvent, context_selector=IKeyNumber)
+def handle_modified_keynumber(event):
+    """Handle modified key number"""
+    content = get_parent(event.object, IKeyNumberContainerTarget)
+    if content is not None:
+        get_current_registry().notify(ObjectModifiedEvent(content))
+
+
+@subscriber(IObjectRemovedEvent, context_selector=IKeyNumber)
+def handle_removed_keynumber(event):
+    """Handle removed key number"""
+    content = get_parent(event.object, IKeyNumberContainerTarget)
+    if content is not None:
+        get_current_registry().notify(ObjectModifiedEvent(content))
+
+
+@adapter_config(context=IKeyNumber, provides=IContentChecker)
+class KeyNumberContentChecker(BaseContentChecker):
+    """Key number content checker"""
+
+    @property
+    def label(self):
+        request = check_request()
+        return II18n(self.context).query_attribute('title', request=request)
+
+    def inner_check(self, request):
+        output = []
+        translate = request.localizer.translate
+        manager = get_parent(self.context, II18nManager)
+        if manager is not None:
+            langs = manager.get_languages()
+        else:
+            negotiator = get_utility(INegotiator)
+            langs = (negotiator.server_language, )
+        i18n = II18n(self.context)
+        for lang in langs:
+            for attr in ('label', 'text'):
+                value = i18n.get_attribute(attr, lang, request)
+                if not value:
+                    field_title = translate(IKeyNumber[attr].title)
+                    if len(langs) == 1:
+                        output.append(translate(MISSING_VALUE).format(field=field_title))
+                    else:
+                        output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang))
+        return output
+
+
+#
+# Key numbers container classes and adapters
+#
+
+@implementer(IKeyNumberContainer)
+class KeyNumberContainer(OrderedContainer):
+    """Key numbers container"""
+
+    last_id = 1
+
+    def append(self, value, notify=True):
+        key = str(self.last_id)
+        if not notify:
+            # pre-locate key number item to avoid multiple notifications
+            locate(value, self, key)
+        self[key] = value
+        self.last_id += 1
+        if not notify:
+            # make sure that key number item is correctly indexed
+            index_object(value)
+
+    def get_visible_items(self):
+        return filter(lambda x: IKeyNumber(x).visible, self.values())
+
+
+@adapter_config(context=IKeyNumberContainerTarget, provides=IKeyNumberContainer)
+def keynumber_container_factory(target):
+    """Key number container factory"""
+    return get_annotation_adapter(target, KEYNUMBER_CONTAINER_KEY, KeyNumberContainer,
+                                  name='++keynumbers++')
+
+
+@adapter_config(name='keynumbers', context=IKeyNumberContainerTarget, provides=ITraversable)
+class KeyNumberContainerNamespace(ContextAdapter):
+    """Key numbers container ++keynumbers++ namespace"""
+
+    def traverse(self, name, furtherpaath=None):
+        return IKeyNumberContainer(self.context)
+
+
+@adapter_config(name='keynumbers', context=IKeyNumberContainerTarget, provides=ISublocations)
+class KeyNumberContainerSublocations(ContextAdapter):
+    """Key numbers container sub-locations adapter"""
+
+    def sublocations(self):
+        return IKeyNumberContainer(self.context).values()
+
+
+@adapter_config(name='keynumbers', context=IKeyNumberContainerTarget, provides=IContentChecker)
+class KeyNumberContainerContentChecker(BaseContentChecker):
+    """Key numbers container content checker"""
+
+    label = _("Key numbers")
+    sep = '\n'
+    weight = 200
+
+    def inner_check(self, request):
+        output = []
+        registry = request.registry
+        for keynumber in IKeyNumberContainer(self.context).values():
+            if not keynumber.visible:
+                continue
+            for name, checker in sorted(registry.getAdapters((keynumber, ), IContentChecker),
+                                        key=lambda x: x[1].weight):
+                output.append('- {0} ({1}):'.format(keynumber.number,
+                                                    II18n(keynumber).query_attribute('label', request=request) or '--'))
+                output.append(checker.get_check_output(request))
+        return output
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/keynumber/interfaces/__init__.py	Wed Jun 13 17:31:17 2018 +0200
@@ -0,0 +1,75 @@
+#
+# Copyright (c) 2008-2018 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_content.interfaces.container import IOrderedContainer
+from zope.annotation.interfaces import IAttributeAnnotatable
+
+# import packages
+from pyams_i18n.schema import I18nTextLineField
+from zope.container.constraints import containers, contains
+from zope.interface import Interface
+from zope.schema import Bool, TextLine
+
+from pyams_content import _
+
+
+KEYNUMBER_CONTAINER_KEY = 'pyams_content.keynumbers'
+
+
+class IKeyNumber(IAttributeAnnotatable):
+    """Base key number interface"""
+
+    containers('.IKeyNumberContainer')
+
+    visible = Bool(title=_("Visible?"),
+                   description=_("Is this key number visible in front-office?"),
+                   required=True,
+                   default=True)
+
+    label = I18nTextLineField(title=_('key-number-label', default="Header"),
+                              description=_("Small text to be displayed above number (according to selected "
+                                            "renderer)"),
+                              required=False)
+
+    number = TextLine(title=_("Number"),
+                      description=_("Key number value"),
+                      required=True)
+
+    unit = I18nTextLineField(title=_('key-number-unit', default="Unit"),
+                             description=_("Displayed unit"),
+                             required=False)
+
+    text = I18nTextLineField(title=_("Associated text"),
+                             description=_("The way this text will be rendered depends on presentation template"),
+                             required=False)
+
+
+class IKeyNumberContainer(IOrderedContainer):
+    """Key numbers container interface"""
+
+    contains(IKeyNumber)
+
+    def append(self, value, notify=True):
+        """Append given key number to container"""
+
+    def get_visible_items(self):
+        """Get list of visible key numbers"""
+
+
+class IKeyNumberContainerTarget(Interface):
+    """Key numbers container target interface"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/keynumber/zmi/__init__.py	Wed Jun 13 17:31:17 2018 +0200
@@ -0,0 +1,257 @@
+#
+# Copyright (c) 2008-2018 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# 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
+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
+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
+from pyams_utils.traversing import get_parent
+from pyams_utils.url import absolute_url
+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 z3c.form import field
+from zope.interface import implementer, Interface
+
+from pyams_content import _
+
+
+class IKeyNumbersView(Interface):
+    """Key numbers view marker interface"""
+
+
+class IKeyNumbersParentForm(Interface):
+    """Key numbers parent form marker interface"""
+
+
+#
+# Key number items table view
+#
+
+class KeyNumbersTable(ProtectedFormObjectMixin, BaseTable):
+    """Key numbers view inner table"""
+
+    prefix = 'keynumbers'
+
+    hide_header = True
+    sortOn = None
+
+    @property
+    def cssClasses(self):
+        classes = ['table', 'table-bordered', 'table-striped', 'table-hover', 'table-tight']
+        permission = self.permission
+        if (not permission) or self.request.has_permission(permission, self.context):
+            classes.append('table-dnd')
+        return {'table': ' '.join(classes)}
+
+    @property
+    def data_attributes(self):
+        attributes = super(KeyNumbersTable, self).data_attributes
+        attributes['table'] = {
+            'data-ams-location': absolute_url(IKeyNumberContainer(self.context), 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
+    def values(self):
+        return list(super(KeyNumbersTable, self).values)
+
+
+@adapter_config(context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IValues)
+class KeyNumbersTableValuesAdapter(ContextRequestViewAdapter):
+    """Key numbers table values adapter"""
+
+    @property
+    def values(self):
+        return IKeyNumberContainer(self.context).values()
+
+
+@adapter_config(name='sorter', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
+class KeyNumbersTableSorterColumn(ProtectedFormObjectMixin, SorterColumn):
+    """Key numbers table sorter column"""
+
+
+@view_config(name='set-keynumbers-order.json', context=IKeyNumberContainer, request_type=IPyAMSLayer,
+             permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
+def set_keynumbers_order(request):
+    """Update key numbers order"""
+    order = list(map(str, json.loads(request.params.get('names'))))
+    request.context.updateOrder(order)
+    return {'status': 'success'}
+
+
+@adapter_config(name='show-hide', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable),
+                provides=IColumn)
+class KeyNumbersTableShowHideColumn(ProtectedFormObjectMixin, VisibilitySwitcherColumn):
+    """Key numbers container visibility switcher column"""
+
+
+@view_config(name='switch-keynumber-visibility.json', context=IKeyNumberContainer, request_type=IPyAMSLayer,
+             permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
+def switch_keynumber_visibility(request):
+    """Switch key number visibility"""
+    return switch_element_visibility(request, IKeyNumberContainer)
+
+
+@adapter_config(name='label', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
+class KeyNumbersTableLabelColumn(I18nColumn, I18nAttrColumn):
+    """Key numbers table label column"""
+
+    _header = _('key-number-label', default="Header")
+    attrName = 'label'
+    weight = 10
+
+    def getValue(self, obj):
+        return super(KeyNumbersTableLabelColumn, self).getValue(obj) or '--'
+
+
+@adapter_config(name='name', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
+class KeyNumbersTableNameColumn(I18nColumn, GetAttrColumn):
+    """Key numbers table number column"""
+
+    _header = _("Number")
+    attrName = 'number'
+    weight = 20
+
+
+@adapter_config(name='unit', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
+class KeyNumbersTableUnitColumn(I18nColumn, I18nAttrColumn):
+    """Key numbers table unit column"""
+
+    _header = _('key-number-unit', default="Unit")
+    attrName = 'unit'
+    weight = 30
+
+    def getValue(self, obj):
+        return super(KeyNumbersTableUnitColumn, self).getValue(obj) or '--'
+
+
+@adapter_config(name='text', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
+class KeyNumbersTableTextColumn(I18nColumn, I18nAttrColumn):
+    """Key numbers table text column"""
+
+    _header = _("Associated text")
+    attrName = 'text'
+    weight = 40
+
+    def getValue(self, obj):
+        return super(KeyNumbersTableTextColumn, self).getValue(obj) or '--'
+
+
+@adapter_config(name='trash', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
+class KeyNumbersTableTrashColumn(ProtectedFormObjectMixin, TrashColumn):
+    """Key numbers table trash column"""
+
+
+@adapter_config(name='keynumbers', context=(IKeyNumberContainerTarget, IPyAMSLayer, IKeyNumbersParentForm),
+                provides=IInnerSubForm)
+@implementer(IKeyNumbersView)
+class KeyNumbersView(InnerTableView):
+    """Key numbers view"""
+
+    title = _("Key numbers")
+
+    table_class = KeyNumbersTable
+    weight = 110
+
+
+#
+# Key numbers forms
+#
+
+@viewlet_config(name='add-keynumber.action', context=IKeyNumberContainerTarget, layer=IPyAMSLayer, view=IKeyNumbersView,
+                manager=IWidgetTitleViewletManager, permission=MANAGE_CONTENT_PERMISSION, weight=1)
+class KeyNumberAddAction(ToolbarAction):
+    """Key number add action"""
+
+    label = _("Add keynumber")
+    label_css_class = 'fa fa-fw fa-plus'
+    url = 'add-keynumber.html'
+    modal_target = True
+
+
+@pagelet_config(name='add-keynumber.html', context=IKeyNumberContainerTarget, layer=IPyAMSLayer,
+                permission=MANAGE_CONTENT_PERMISSION)
+@ajax_config(name='add-keynumber.json', context=IParagraphContainerTarget, layer=IPyAMSLayer,
+             base=AJAXAddForm)
+class KeyNumberAddForm(AdminDialogAddForm):
+    """Key number add form"""
+
+    legend = _("Add new keynumber")
+    icon_css_class = 'fa fa-fw fa-dashboard'
+
+    fields = field.Fields(IKeyNumber).omit('__parent__', '__name__', 'visible')
+    edit_permission = MANAGE_CONTENT_PERMISSION
+
+    def create(self, data):
+        return KeyNumber()
+
+    def add(self, object):
+        IKeyNumberContainer(self.context).append(object)
+
+    def get_ajax_output(self, changes):
+        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), ]
+        }
+
+
+@pagelet_config(name='properties.html', context=IKeyNumber, layer=IPyAMSLayer, permission=MANAGE_CONTENT_PERMISSION)
+@ajax_config(name='properties.json', context=IKeyNumber, layer=IPyAMSLayer)
+class KeyNumberPropertiesEditForm(AdminDialogEditForm):
+    """Key number properties edit form"""
+
+    prefix = 'keynumber_properties.'
+
+    legend = _("Edit keynumber properties")
+    icon_css_class = 'fa fa-fw fa-dashboard'
+
+    fields = field.Fields(IKeyNumber).omit('__parent__', '__name__', 'visible')
+    edit_permission = MANAGE_CONTENT_PERMISSION
+
+    def get_ajax_output(self, changes):
+        output = super(self.__class__, self).get_ajax_output(changes)
+        updated = changes.get(IKeyNumber, ())
+        if updated:
+            target = get_parent(self.context, IKeyNumberContainerTarget)
+            output.setdefault('events', []).append(
+                get_json_table_row_refresh_event(target, self.request, KeyNumbersTable, self.context))
+        return output
--- a/src/pyams_content/component/paragraph/interfaces/keynumber.py	Wed Jun 13 16:34:37 2018 +0200
+++ b/src/pyams_content/component/paragraph/interfaces/keynumber.py	Wed Jun 13 17:31:17 2018 +0200
@@ -16,66 +16,15 @@
 # import standard library
 
 # import interfaces
+from pyams_content.component.keynumber.interfaces import IKeyNumberContainerTarget
 from pyams_content.component.paragraph import IBaseParagraph
-from pyams_content.interfaces.container import IOrderedContainer
-from zope.annotation.interfaces import IAttributeAnnotatable
 
 # import packages
-from pyams_i18n.schema import I18nTextLineField
-from zope.container.constraints import containers, contains
-from zope.interface import Interface
 from zope.schema import Bool, Choice, TextLine
 
 from pyams_content import _
 
 
-KEYNUMBER_CONTAINER_KEY = 'pyams_content.keynumbers'
-
-
-class IKeyNumber(IAttributeAnnotatable):
-    """Base key number interface"""
-
-    containers('.IKeyNumberContainer')
-
-    visible = Bool(title=_("Visible?"),
-                   description=_("Is this key number visible in front-office?"),
-                   required=True,
-                   default=True)
-
-    label = I18nTextLineField(title=_('key-number-label', default="Header"),
-                              description=_("Small text to be displayed above number (according to selected "
-                                            "renderer)"),
-                              required=False)
-
-    number = TextLine(title=_("Number"),
-                      description=_("Key number value"),
-                      required=True)
-
-    unit = I18nTextLineField(title=_('key-number-unit', default="Unit"),
-                             description=_("Displayed unit"),
-                             required=False)
-
-    text = I18nTextLineField(title=_("Associated text"),
-                             description=_("The way this text will be rendered depends on presentation template"),
-                             required=False)
-
-
-class IKeyNumberContainer(IOrderedContainer):
-    """Key numbers container interface"""
-
-    contains(IKeyNumber)
-
-    def append(self, value, notify=True):
-        """Append given key number to container"""
-
-    def get_visible_items(self):
-        """Get list of visible key numbers"""
-
-
-class IKeyNumberContainerTarget(Interface):
-    """Key numbers container target interface"""
-
-
 KEYNUMBER_PARAGRAPH_TYPE = 'KeyNumbers'
 KEYNUMBER_PARAGRAPH_NAME = _("Key numbers")
 KEYNUMBER_PARAGRAPH_RENDERERS = 'PyAMS.keynumbers.renderers'
--- a/src/pyams_content/component/paragraph/keynumber.py	Wed Jun 13 16:34:37 2018 +0200
+++ b/src/pyams_content/component/paragraph/keynumber.py	Wed Jun 13 17:31:17 2018 +0200
@@ -14,189 +14,27 @@
 
 
 # import standard library
-from persistent import Persistent
 
 # import interfaces
 from pyams_content.component.paragraph.interfaces import IParagraphFactory
-from pyams_content.component.paragraph.interfaces.keynumber import IKeyNumber, IKeyNumberContainer, \
-    IKeyNumberContainerTarget, KEYNUMBER_CONTAINER_KEY, IKeyNumberParagraph, KEYNUMBER_PARAGRAPH_TYPE, \
+from pyams_content.component.paragraph.interfaces.keynumber import IKeyNumberParagraph, KEYNUMBER_PARAGRAPH_TYPE, \
     KEYNUMBER_PARAGRAPH_RENDERERS, KEYNUMBER_PARAGRAPH_NAME
 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.component.paragraph import BaseParagraph, BaseParagraphFactory, BaseParagraphContentChecker
-from pyams_content.features.checker import BaseContentChecker
 from pyams_content.features.renderer import RenderersVocabulary
-from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
+from pyams_utils.adapter import adapter_config
 from pyams_utils.factory import factory_config
-from pyams_utils.registry import get_current_registry, get_utility, utility_config
+from pyams_utils.registry import get_utility, utility_config
 from pyams_utils.request import check_request
 from pyams_utils.traversing import get_parent
 from pyams_utils.vocabulary import vocabulary_config
-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 ObjectCreatedEvent, ObjectModifiedEvent
-from zope.location import locate
 from zope.schema.fieldproperty import FieldProperty
 
 
-#
-# Key number class and adapters
-#
-
-@implementer(IKeyNumber)
-class KeyNumber(Persistent, Contained):
-    """Key number persistent class"""
-
-    visible = FieldProperty(IKeyNumber['visible'])
-    label = FieldProperty(IKeyNumber['label'])
-    number = FieldProperty(IKeyNumber['number'])
-    unit = FieldProperty(IKeyNumber['unit'])
-    text = FieldProperty(IKeyNumber['text'])
-
-
-@adapter_config(context=IKeyNumber, provides=IFormContextPermissionChecker)
-class KeyNumberPermissionChecker(ContextAdapter):
-    """Key number permission checker"""
-
-    @property
-    def edit_permission(self):
-        content = get_parent(self.context, IKeyNumberContainerTarget)
-        return IFormContextPermissionChecker(content).edit_permission
-
-
-@subscriber(IObjectAddedEvent, context_selector=IKeyNumber)
-def handle_added_keynumber(event):
-    """Handle added key number"""
-    content = get_parent(event.object, IKeyNumberContainerTarget)
-    if content is not None:
-        get_current_registry().notify(ObjectModifiedEvent(content))
-
-
-@subscriber(IObjectModifiedEvent, context_selector=IKeyNumber)
-def handle_modified_keynumber(event):
-    """Handle modified key number"""
-    content = get_parent(event.object, IKeyNumberContainerTarget)
-    if content is not None:
-        get_current_registry().notify(ObjectModifiedEvent(content))
-
-
-@subscriber(IObjectRemovedEvent, context_selector=IKeyNumber)
-def handle_removed_keynumber(event):
-    """Handle removed key number"""
-    content = get_parent(event.object, IKeyNumberContainerTarget)
-    if content is not None:
-        get_current_registry().notify(ObjectModifiedEvent(content))
-
-
-@adapter_config(context=IKeyNumber, provides=IContentChecker)
-class KeyNumberContentChecker(BaseContentChecker):
-    """Key number content checker"""
-
-    @property
-    def label(self):
-        request = check_request()
-        return II18n(self.context).query_attribute('title', request=request)
-
-    def inner_check(self, request):
-        output = []
-        translate = request.localizer.translate
-        manager = get_parent(self.context, II18nManager)
-        if manager is not None:
-            langs = manager.get_languages()
-        else:
-            negotiator = get_utility(INegotiator)
-            langs = (negotiator.server_language, )
-        i18n = II18n(self.context)
-        for lang in langs:
-            for attr in ('label', 'text'):
-                value = i18n.get_attribute(attr, lang, request)
-                if not value:
-                    field_title = translate(IKeyNumber[attr].title)
-                    if len(langs) == 1:
-                        output.append(translate(MISSING_VALUE).format(field=field_title))
-                    else:
-                        output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang))
-        return output
-
-
-#
-# Key numbers container classes and adapters
-#
-
-@implementer(IKeyNumberContainer)
-class KeyNumberContainer(OrderedContainer):
-    """Key numbers container"""
-
-    last_id = 1
-
-    def append(self, value, notify=True):
-        key = str(self.last_id)
-        if not notify:
-            # pre-locate key number item to avoid multiple notifications
-            locate(value, self, key)
-        self[key] = value
-        self.last_id += 1
-        if not notify:
-            # make sure that key number item is correctly indexed
-            index_object(value)
-
-    def get_visible_items(self):
-        return filter(lambda x: IKeyNumber(x).visible, self.values())
-
-
-@adapter_config(context=IKeyNumberContainerTarget, provides=IKeyNumberContainer)
-def keynumber_container_factory(target):
-    """Key number container factory"""
-    return get_annotation_adapter(target, KEYNUMBER_CONTAINER_KEY, KeyNumberContainer, name='++keynumbers++')
-
-
-@adapter_config(name='keynumbers', context=IKeyNumberContainerTarget, provides=ITraversable)
-class KeyNumberContainerNamespace(ContextAdapter):
-    """Key numbers container ++keynumbers++ namespace"""
-
-    def traverse(self, name, furtherpaath=None):
-        return IKeyNumberContainer(self.context)
-
-
-@adapter_config(name='keynumbers', context=IKeyNumberContainerTarget, provides=ISublocations)
-class KeyNumberContainerSublocations(ContextAdapter):
-    """Key numbers container sub-locations adapter"""
-
-    def sublocations(self):
-        return IKeyNumberContainer(self.context).values()
-
-
-@adapter_config(name='keynumbers', context=IKeyNumberContainerTarget, provides=IContentChecker)
-class KeyNumberContainerContentChecker(BaseContentChecker):
-    """Key numbers container content checker"""
-
-    label = KEYNUMBER_PARAGRAPH_NAME
-    sep = '\n'
-    weight = 200
-
-    def inner_check(self, request):
-        output = []
-        registry = request.registry
-        for keynumber in IKeyNumberContainer(self.context).values():
-            if not keynumber.visible:
-                continue
-            for name, checker in sorted(registry.getAdapters((keynumber, ), IContentChecker),
-                                        key=lambda x: x[1].weight):
-                output.append('- {0} ({1}):'.format(keynumber.number,
-                                                    II18n(keynumber).query_attribute('label', request=request) or '--'))
-                output.append(checker.get_check_output(request))
-        return output
-
-
 @implementer(IKeyNumberParagraph)
 @factory_config(provided=IKeyNumberParagraph)
 class KeyNumberParagraph(BaseParagraph):
--- a/src/pyams_content/component/paragraph/zmi/keynumber.py	Wed Jun 13 16:34:37 2018 +0200
+++ b/src/pyams_content/component/paragraph/zmi/keynumber.py	Wed Jun 13 17:31:17 2018 +0200
@@ -14,60 +14,39 @@
 
 
 # import standard library
-import json
 
 # import interfaces
 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer
-from pyams_content.component.paragraph.interfaces.keynumber import KEYNUMBER_PARAGRAPH_TYPE, IKeyNumberParagraph, \
-    IKeyNumberContainer, IKeyNumberContainerTarget, IKeyNumber
+from pyams_content.component.paragraph.interfaces.keynumber import KEYNUMBER_PARAGRAPH_TYPE, IKeyNumberParagraph
 from pyams_content.component.paragraph.zmi import IParagraphContainerView, IParagraphEditFormButtons
 from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
 from pyams_content.shared.common import IWfSharedContent
-from pyams_form.interfaces.form import IInnerForm, IInnerSubForm
+from pyams_form.interfaces.form import IInnerForm
 from pyams_i18n.interfaces import II18n
-from pyams_skin.interfaces.viewlet import IToolbarAddingMenu, IWidgetTitleViewletManager
+from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
 from pyams_skin.layer import IPyAMSLayer
 from z3c.form.interfaces import INPUT_MODE
-from z3c.table.interfaces import IValues, IColumn
 
 # import packages
-from pyams_content.component.paragraph.keynumber import KeyNumberParagraph, KeyNumber
+from pyams_content.component.keynumber.zmi import IKeyNumbersParentForm
+from pyams_content.component.paragraph.keynumber import KeyNumberParagraph
 from pyams_content.component.paragraph.zmi import BaseParagraphAddMenu, BaseParagraphAJAXAddForm, \
     BaseParagraphPropertiesEditForm, BaseParagraphAJAXEditForm
 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
-from pyams_form.form import AJAXAddForm, ajax_config
-from pyams_form.security import ProtectedFormObjectMixin
-from pyams_i18n.column import I18nAttrColumn
+from pyams_form.form import ajax_config
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.container import switch_element_visibility
-from pyams_skin.event import get_json_widget_refresh_event, get_json_switched_table_refresh_event, \
-    get_json_table_row_refresh_event
-from pyams_skin.table import BaseTable, SorterColumn, I18nColumn, VisibilitySwitcherColumn, TrashColumn
-from pyams_skin.viewlet.toolbar import ToolbarAction
-from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
+from pyams_skin.event import get_json_widget_refresh_event
+from pyams_utils.adapter import adapter_config
 from pyams_utils.traversing import get_parent
-from pyams_utils.url import absolute_url
 from pyams_viewlet.viewlet import viewlet_config
-from pyams_zmi.form import AdminDialogAddForm, AdminDialogEditForm
-from pyams_zmi.zmi.table import InnerTableView
-from pyramid.decorator import reify
-from pyramid.view import view_config
+from pyams_zmi.form import AdminDialogAddForm
 from z3c.form import field, button
-from z3c.table.column import GetAttrColumn
 from zope.interface import implementer, Interface
 
 from pyams_content import _
 
 
-class IKeyNumbersView(Interface):
-    """Key numbers view marker interface"""
-
-
-class IKeyNumbersParentForm(Interface):
-    """Key numbers parent form marker interface"""
-
-
 @viewlet_config(name='add-keynumber-paragraph.menu', context=IParagraphContainerTarget, view=IParagraphContainerView,
                 layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=600)
 class KeyNumberParagraphAddMenu(BaseParagraphAddMenu):
@@ -145,203 +124,3 @@
             output.setdefault('events', []).append(
                 get_json_widget_refresh_event(self.context, self.request, KeyNumberParagraphInnerEditForm, 'renderer'))
         return output
-
-
-#
-# Key number items table view
-#
-
-class KeyNumbersTable(ProtectedFormObjectMixin, BaseTable):
-    """Key numbers view inner table"""
-
-    prefix = 'keynumbers'
-
-    hide_header = True
-    sortOn = None
-
-    @property
-    def cssClasses(self):
-        classes = ['table', 'table-bordered', 'table-striped', 'table-hover', 'table-tight']
-        permission = self.permission
-        if (not permission) or self.request.has_permission(permission, self.context):
-            classes.append('table-dnd')
-        return {'table': ' '.join(classes)}
-
-    @property
-    def data_attributes(self):
-        attributes = super(KeyNumbersTable, self).data_attributes
-        attributes['table'] = {
-            'id': self.id,
-            'data-ams-location': absolute_url(IKeyNumberContainer(self.context), 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
-    def values(self):
-        return list(super(KeyNumbersTable, self).values)
-
-
-@adapter_config(context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IValues)
-class KeyNumbersTableValuesAdapter(ContextRequestViewAdapter):
-    """Key numbers table values adapter"""
-
-    @property
-    def values(self):
-        return IKeyNumberContainer(self.context).values()
-
-
-@adapter_config(name='sorter', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
-class KeyNumbersTableSorterColumn(ProtectedFormObjectMixin, SorterColumn):
-    """Key numbers table sorter column"""
-
-
-@view_config(name='set-keynumbers-order.json', context=IKeyNumberContainer, request_type=IPyAMSLayer,
-             permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-def set_keynumbers_order(request):
-    """Update key numbers order"""
-    order = list(map(str, json.loads(request.params.get('names'))))
-    request.context.updateOrder(order)
-    return {'status': 'success'}
-
-
-@adapter_config(name='show-hide', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable),
-                provides=IColumn)
-class KeyNumbersTableShowHideColumn(ProtectedFormObjectMixin, VisibilitySwitcherColumn):
-    """Key numbers container visibility switcher column"""
-
-
-@view_config(name='switch-keynumber-visibility.json', context=IKeyNumberContainer, request_type=IPyAMSLayer,
-             permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-def switch_keynumber_visibility(request):
-    """Switch key number visibility"""
-    return switch_element_visibility(request, IKeyNumberContainer)
-
-
-@adapter_config(name='label', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
-class KeyNumbersTableLabelColumn(I18nColumn, I18nAttrColumn):
-    """Key numbers table label column"""
-
-    _header = _('key-number-label', default="Header")
-    attrName = 'label'
-    weight = 10
-
-    def getValue(self, obj):
-        return super(KeyNumbersTableLabelColumn, self).getValue(obj) or '--'
-
-
-@adapter_config(name='name', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
-class KeyNumbersTableNameColumn(I18nColumn, GetAttrColumn):
-    """Key numbers table number column"""
-
-    _header = _("Number")
-    attrName = 'number'
-    weight = 20
-
-
-@adapter_config(name='unit', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
-class KeyNumbersTableUnitColumn(I18nColumn, I18nAttrColumn):
-    """Key numbers table unit column"""
-
-    _header = _('key-number-unit', default="Unit")
-    attrName = 'unit'
-    weight = 30
-
-    def getValue(self, obj):
-        return super(KeyNumbersTableUnitColumn, self).getValue(obj) or '--'
-
-
-@adapter_config(name='text', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
-class KeyNumbersTableTextColumn(I18nColumn, I18nAttrColumn):
-    """Key numbers table text column"""
-
-    _header = _("Associated text")
-    attrName = 'text'
-    weight = 40
-
-    def getValue(self, obj):
-        return super(KeyNumbersTableTextColumn, self).getValue(obj) or '--'
-
-
-@adapter_config(name='trash', context=(IKeyNumberContainerTarget, IPyAMSLayer, KeyNumbersTable), provides=IColumn)
-class KeyNumbersTableTrashColumn(ProtectedFormObjectMixin, TrashColumn):
-    """Key numbers table trash column"""
-
-
-@adapter_config(name='keynumbers', context=(IKeyNumberContainerTarget, IPyAMSLayer, IKeyNumbersParentForm),
-                provides=IInnerSubForm)
-@implementer(IKeyNumbersView)
-class KeyNumbersView(InnerTableView):
-    """Key numbers view"""
-
-    title = _("Key numbers")
-
-    table_class = KeyNumbersTable
-    weight = 110
-
-
-#
-# Key numbers forms
-#
-
-@viewlet_config(name='add-keynumber.action', context=IKeyNumberContainerTarget, layer=IPyAMSLayer, view=IKeyNumbersView,
-                manager=IWidgetTitleViewletManager, permission=MANAGE_CONTENT_PERMISSION, weight=1)
-class KeyNumberAddAction(ToolbarAction):
-    """Key number add action"""
-
-    label = _("Add keynumber")
-    label_css_class = 'fa fa-fw fa-plus'
-    url = 'add-keynumber.html'
-    modal_target = True
-
-
-@pagelet_config(name='add-keynumber.html', context=IKeyNumberContainerTarget, layer=IPyAMSLayer,
-                permission=MANAGE_CONTENT_PERMISSION)
-@ajax_config(name='add-keynumber.json', context=IParagraphContainerTarget, layer=IPyAMSLayer,
-             base=AJAXAddForm)
-class KeyNumberAddForm(AdminDialogAddForm):
-    """Key number add form"""
-
-    legend = _("Add new keynumber")
-    icon_css_class = 'fa fa-fw fa-dashboard'
-
-    fields = field.Fields(IKeyNumber).omit('__parent__', '__name__', 'visible')
-    edit_permission = MANAGE_CONTENT_PERMISSION
-
-    def create(self, data):
-        return KeyNumber()
-
-    def add(self, object):
-        IKeyNumberContainer(self.context).append(object)
-
-    def get_ajax_output(self, changes):
-        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), ]
-        }
-
-
-@pagelet_config(name='properties.html', context=IKeyNumber, layer=IPyAMSLayer, permission=MANAGE_CONTENT_PERMISSION)
-@ajax_config(name='properties.json', context=IKeyNumber, layer=IPyAMSLayer)
-class KeyNumberPropertiesEditForm(AdminDialogEditForm):
-    """Key number properties edit form"""
-
-    prefix = 'keynumber_properties.'
-
-    legend = _("Edit keynumber properties")
-    icon_css_class = 'fa fa-fw fa-dashboard'
-
-    fields = field.Fields(IKeyNumber).omit('__parent__', '__name__', 'visible')
-    edit_permission = MANAGE_CONTENT_PERMISSION
-
-    def get_ajax_output(self, changes):
-        output = super(self.__class__, self).get_ajax_output(changes)
-        updated = changes.get(IKeyNumber, ())
-        if updated:
-            target = get_parent(self.context, IKeyNumberContainerTarget)
-            output.setdefault('events', []).append(
-                get_json_table_row_refresh_event(target, self.request, KeyNumbersTable, self.context))
-        return output
--- a/src/pyams_content/generations/__init__.py	Wed Jun 13 16:34:37 2018 +0200
+++ b/src/pyams_content/generations/__init__.py	Wed Jun 13 17:31:17 2018 +0200
@@ -55,13 +55,20 @@
 
 
 RENAMED_CLASSES = {
-    'pyams_content.shared.common.review ReviewComment': 'pyams_content.features.review ReviewComment',
+    'pyams_content.shared.common.review ReviewComment':
+        'pyams_content.features.review ReviewComment',
     'pyams_content.shared.common.review ReviewCommentsContainer':
         'pyams_content.features.review ReviewCommentsContainer',
     'pyams_portal.portlets.content ContentPortletSettings':
         'pyams_content.portlet.content SharedContentPortletSettings',
-    'pyams_content.component.association.menu MenusContainer': 'pyams_content.features.menu MenusContainer',
-    'pyams_content.component.association.menu Menu': 'pyams_content.features.menu Menu'
+    'pyams_content.component.association.menu MenusContainer':
+        'pyams_content.features.menu MenusContainer',
+    'pyams_content.component.association.menu Menu':
+        'pyams_content.features.menu Menu',
+    'pyams_content.component.paragraph.keynumber KeyNumber':
+        'pyams_content.component.keynumber KeyNumber',
+    'pyams_content.component.paragraph.keynumber KeyNumberContainer':
+        'pyams_content.component.keynumber KeyNumberContainer'
 }