Added site tree view
authorThierry Florac <thierry.florac@onf.fr>
Mon, 20 Jun 2016 12:26:37 +0200
changeset 44 6931ae3912c9
parent 43 2136e95fb9a5
child 45 74b7fbb59a92
Added site tree view
src/pyams_content/shared/zmi/__init__.py
src/pyams_content/shared/zmi/interfaces/__init__.py
src/pyams_content/shared/zmi/sites.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/zmi/__init__.py	Mon Jun 20 12:26:37 2016 +0200
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2008-2015 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
+
+# import packages
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/zmi/interfaces/__init__.py	Mon Jun 20 12:26:37 2016 +0200
@@ -0,0 +1,25 @@
+#
+# Copyright (c) 2008-2015 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_skin.interfaces.viewlet import IMenuItem
+
+# import packages
+
+
+class ISiteTreeMenu(IMenuItem):
+    """Site tree menu marker interface"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/zmi/sites.py	Mon Jun 20 12:26:37 2016 +0200
@@ -0,0 +1,130 @@
+#
+# Copyright (c) 2008-2015 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.shared.common.interfaces import ISharedSite, ISharedTool
+from pyams_content.shared.common.interfaces.zmi import IDashboardTable
+from pyams_content.shared.zmi.interfaces import ISiteTreeMenu
+from pyams_skin.interfaces import IInnerPage, IPageHeader
+from pyams_skin.interfaces.container import ITableWithActions
+from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
+from pyams_zmi.interfaces.menu import ISiteManagementMenu
+from pyams_zmi.layer import IAdminLayer
+from z3c.table.interfaces import IColumn, IValues
+from zope.component.interfaces import ISite
+
+# import packages
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_skin.container import ContainerView
+from pyams_skin.page import DefaultPageHeaderAdapter
+from pyams_skin.table import BaseTable, TrashColumn
+from pyams_skin.viewlet.menu import MenuItem
+from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
+from pyams_utils.url import absolute_url
+from pyams_viewlet.manager import viewletmanager_config
+from pyams_viewlet.viewlet import viewlet_config
+from pyams_zmi.view import AdminView
+from pyramid.view import view_config
+from zope.interface import implementer, Interface
+
+from pyams_content import _
+
+
+#
+# Sites and blogs view
+#
+
+@viewlet_config(name='site-tree.menu', layer=IAdminLayer, context=ISite, manager=ISiteManagementMenu,
+                permission=VIEW_SYSTEM_PERMISSION, weight=5)
+@viewletmanager_config(name='site-tree.menu', layer=IAdminLayer, context=ISite, provides=ISiteTreeMenu)
+@implementer(ISiteTreeMenu)
+class SiteTreeMenu(MenuItem):
+    """Site tree menu"""
+
+    label = _("Site tree")
+    icon_class = 'fa-sitemap'
+    url = '#site-tree.html'
+
+
+@implementer(IDashboardTable, ITableWithActions)
+class SiteTreeTable(BaseTable):
+    """Site tree table"""
+
+    id = 'site_tree_table'
+    title = _("Blogs and shared sites")
+
+    @property
+    def data_attributes(self):
+        attributes = super(SiteTreeTable, self).data_attributes
+        attributes['table'] = {'data-ams-location': absolute_url(self.context, self.request),
+                               'data-ams-delete-target': 'delete-shared-site.json'}
+        return attributes
+
+
+@adapter_config(name='trash', context=(Interface, IAdminLayer, SiteTreeTable), provides=IColumn)
+class SiteTreeTrashColumn(TrashColumn):
+    """Site tree trash column"""
+
+    icon_hint = _("Delete shared site")
+    permission = MANAGE_SYSTEM_PERMISSION
+
+
+@adapter_config(context=(ISite, IAdminLayer, SiteTreeTable), provides=IValues)
+class SiteTreValuesAdapter(ContextRequestViewAdapter):
+    """Site tree values adapter"""
+
+    @property
+    def values(self):
+        return [value for value in self.context.values()
+                if ISharedTool.providedBy(value) or ISharedSite.providedBy(value)]
+
+
+@pagelet_config(name='site-tree.html', context=ISite, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
+@implementer(IInnerPage)
+class SiteTreeView(AdminView, ContainerView):
+    """Site tree view"""
+
+    table_class = SiteTreeTable
+
+    def __init__(self, context, request):
+        super(SiteTreeView, self).__init__(context, request)
+
+
+@adapter_config(context=(ISite, IAdminLayer, SiteTreeView), provides=IPageHeader)
+class SiteViewHeaderAdapter(DefaultPageHeaderAdapter):
+    """Site tree view header adapter"""
+
+    icon_class = 'fa fa-fw fa-sitemap'
+
+
+@view_config(name='delete-shared-site.json', context=ISite, request_type=IPyAMSLayer,
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
+def delete_shared_site(request):
+    """Delete shared site from site manager"""
+    translate = request.localizer.translate
+    name = request.params.get('object_name')
+    if not name:
+        return {'status': 'message',
+                'messagebox': {'status': 'error',
+                               'content': translate(_("No provided object_name argument!"))}}
+    if name not in request.context:
+        return {'status': 'message',
+                'messagebox': {'status': 'error',
+                               'content': translate(_("Given site name doesn't exist!"))}}
+    del request.context[name]
+    return {'status': 'success'}