Added internal reference target column to menus
authorThierry Florac <thierry.florac@onf.fr>
Mon, 12 Nov 2018 12:07:52 +0100
changeset 1076 93f78438ff8c
parent 1075 1102a2738e47
child 1077 24ab1360b343
Added internal reference target column to menus
src/pyams_content/features/menu/zmi/__init__.py
--- a/src/pyams_content/features/menu/zmi/__init__.py	Mon Nov 12 11:20:34 2018 +0100
+++ b/src/pyams_content/features/menu/zmi/__init__.py	Mon Nov 12 12:07:52 2018 +0100
@@ -19,6 +19,7 @@
 from pyramid.renderers import render
 from pyramid.view import view_config
 from z3c.form import field
+from z3c.table.column import GetAttrColumn
 from z3c.table.interfaces import IColumn, IValues
 from zope.interface import Interface, alsoProvides, implementer
 
@@ -32,8 +33,10 @@
 from pyams_form.form import AJAXAddForm, AJAXEditForm, ajax_config
 from pyams_form.interfaces.form import IFormContextPermissionChecker
 from pyams_i18n.column import I18nAttrColumn
+from pyams_i18n.interfaces import II18n
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_portal.interfaces import MANAGE_TEMPLATE_PERMISSION
+from pyams_sequence.interfaces import ISequentialIdInfo
 from pyams_skin.container import delete_container_element, switch_element_visibility
 from pyams_skin.event import get_json_switched_table_refresh_event, get_json_table_row_refresh_event
 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu, IWidgetTitleViewletManager
@@ -220,6 +223,23 @@
         return render('templates/menu-name-cell.pt', {'context': item}, request=self.request)
 
 
+@adapter_config(name='reference', context=(IMenusContainerTarget, IPyAMSLayer, MenusTable), provides=IColumn)
+class MenusTableReferenceColumn(I18nColumn, GetAttrColumn):
+    """Menus table reference column"""
+
+    _header = _("Inner content")
+    weight = 15
+
+    def getValue(self, obj):
+        target = obj.target
+        if target is not None:
+            sequence = ISequentialIdInfo(target)
+            return '{0} ({1})'.format(II18n(target).query_attribute('title'),
+                                      sequence.get_short_oid())
+        else:
+            return '--'
+
+
 @adapter_config(name='trash', context=(IMenusContainerTarget, IPyAMSLayer, MenusTable), provides=IColumn)
 class MenusTableTrashColumn(TrashColumn):
     """Menus table trash column"""