--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/reference/__init__.py Sat Mar 10 02:35:15 2018 +0100
@@ -0,0 +1,66 @@
+#
+# 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
+from persistent import Persistent
+
+# import interfaces
+from pyams_content.reference.interfaces import IReferenceManager, IReferenceTable, IReferenceInfo
+from pyams_i18n.interfaces import II18nManager
+from zope.component.interfaces import ISite
+from zope.lifecycleevent import IObjectAddedEvent
+
+# import packages
+from pyams_utils.traversing import get_parent
+from pyramid.events import subscriber
+from zope.container.contained import Contained
+from zope.container.folder import Folder
+from zope.interface import implementer
+from zope.schema.fieldproperty import FieldProperty
+
+
+@implementer(IReferenceManager)
+class ReferencesManager(Folder):
+ """References tables container"""
+
+ title = FieldProperty(IReferenceManager['title'])
+ short_name = FieldProperty(IReferenceManager['short_name'])
+
+
+@subscriber(IObjectAddedEvent, context_selector=IReferenceManager)
+def handle_added_references_manager(event):
+ """Handle new references manager"""
+ site = get_parent(event.object, ISite)
+ registry = site.getSiteManager()
+ if registry is not None:
+ registry.registerUtility(event.object, IReferenceManager)
+
+
+@implementer(IReferenceTable, II18nManager)
+class ReferenceTable(Folder):
+ """References table"""
+
+ title = FieldProperty(IReferenceTable['title'])
+ short_name = FieldProperty(IReferenceTable['short_name'])
+
+ languages = FieldProperty(II18nManager['languages'])
+
+
+@implementer(IReferenceInfo)
+class ReferenceInfo(Persistent, Contained):
+ """Reference record"""
+
+ title = FieldProperty(IReferenceInfo['title'])
+ short_name = FieldProperty(IReferenceInfo['short_name'])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/reference/interfaces/__init__.py Sat Mar 10 02:35:15 2018 +0100
@@ -0,0 +1,42 @@
+#
+# 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.interfaces import IBaseContent
+from zope.container.interfaces import IContainer
+
+# import packages
+from zope.container.constraints import containers, contains
+
+
+class IReferenceInfo(IBaseContent):
+ """Base reference interface"""
+
+ containers('.IReferenceTable')
+
+
+class IReferenceTable(IBaseContent):
+ """Reference table interface"""
+
+ containers('.IReferenceTableContainer')
+ contains(IReferenceInfo)
+
+
+class IReferenceManager(IBaseContent, IContainer):
+ """References tables container"""
+
+ contains(IReferenceTable)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/reference/zmi/__init__.py Sat Mar 10 02:35:15 2018 +0100
@@ -0,0 +1,74 @@
+#
+# 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.interfaces import MANAGE_SITE_ROOT_PERMISSION
+from pyams_content.reference.interfaces import IReferenceManager, IReferenceInfo
+from pyams_i18n.interfaces import II18n
+from pyams_skin.interfaces.container import ITableElementName
+from pyams_skin.interfaces.viewlet import ITopLinksViewletManager, IBreadcrumbItem
+from pyams_skin.layer import IPyAMSLayer
+from pyams_zmi.layer import IAdminLayer
+
+# import packages
+from pyams_skin.viewlet.breadcrumb import BreadcrumbItem
+from pyams_skin.viewlet.toplinks import TopLinksViewlet, TopLinksMenu
+from pyams_utils.adapter import adapter_config, ContextRequestAdapter
+from pyams_utils.registry import get_local_registry
+from pyams_utils.url import absolute_url
+from pyams_viewlet.viewlet import viewlet_config
+from zope.interface import Interface
+
+from pyams_content import _
+
+
+@viewlet_config(name='references.menu', layer=IAdminLayer, manager=ITopLinksViewletManager,
+ permission=MANAGE_SITE_ROOT_PERMISSION, weight=70)
+class ReferencesMenu(TopLinksViewlet):
+ """References tables menu"""
+
+ label = ''
+ css_class = 'top-menu bordered margin-top-10'
+ dropdown_label = _("References")
+
+ def update(self):
+ super(ReferencesMenu, self).update()
+ registry = get_local_registry()
+ references = registry.queryUtility(IReferenceManager)
+ if references is not None:
+ for table in references.values():
+ menu = TopLinksMenu(self.context, self.request, self.__parent__, self)
+ menu.label = II18n(table).query_attribute('short_name', request=self.request) or table.__name__
+ menu.url = absolute_url(table, self.request, 'admin#contents.html')
+ self.viewlets.append(menu)
+
+
+@adapter_config(context=(IReferenceManager, IPyAMSLayer), provides=IBreadcrumbItem)
+class ReferenceManagerBreadcrumbAdapter(BreadcrumbItem):
+ """References tables manager breadcrumb adapter"""
+
+ label = _("References tables")
+ url = None
+
+
+@adapter_config(context=(IReferenceInfo, Interface), provides=ITableElementName)
+class ReferenceInfoTableElementName(ContextRequestAdapter):
+ """Reference table element name"""
+
+ @property
+ def name(self):
+ return II18n(self.context).query_attribute('title', request=self.request)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/reference/zmi/table.py Sat Mar 10 02:35:15 2018 +0100
@@ -0,0 +1,157 @@
+#
+# 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.interfaces import MANAGE_SITE_ROOT_PERMISSION
+from pyams_content.reference.interfaces import IReferenceTable
+from pyams_i18n.interfaces import II18n
+from pyams_skin.interfaces import IInnerPage, IPageHeader
+from pyams_skin.interfaces.viewlet import IBreadcrumbItem
+from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+from pyams_zmi.interfaces.menu import ISiteManagementMenu, IPropertiesMenu
+from pyams_zmi.layer import IAdminLayer
+from z3c.table.interfaces import IValues, IColumn
+
+# import packages
+from pyams_form.form import AJAXEditForm
+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.breadcrumb import BreadcrumbItem
+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.form import AdminDialogEditForm
+from pyams_zmi.view import AdminView
+from pyramid.view import view_config
+from z3c.form import field
+from zope.interface import implementer
+
+from pyams_content import _
+
+
+#
+# Table properties
+#
+
+@adapter_config(context=(IReferenceTable, IPyAMSLayer), provides=IBreadcrumbItem)
+class ReferenceTableBreadcrumbAdapter(BreadcrumbItem):
+ """References table breadcrumb adapter"""
+
+ @property
+ def label(self):
+ return II18n(self.context).query_attribute('short_name', request=self.request)
+
+ css_class = 'strong'
+
+
+@viewlet_config(name='contents.menu', context=IReferenceTable, layer=IAdminLayer,
+ manager=ISiteManagementMenu, permission=VIEW_SYSTEM_PERMISSION, weight=1)
+@viewletmanager_config(name='contents.menu', layer=IAdminLayer, provides=IPropertiesMenu)
+@implementer(IPropertiesMenu)
+class ReferenceTableContentsMenu(MenuItem):
+ """References table contents menu"""
+
+ label = _("Contents")
+ icon_class = 'fa-table'
+ url = '#contents.html'
+
+
+class ReferenceTableContentsTable(BaseTable):
+ """References table contents table"""
+
+ title = _("Table contents")
+
+ @property
+ def data_attributes(self):
+ attributes = super(ReferenceTableContentsTable, self).data_attributes
+ table_attrs = {'data-ams-location': absolute_url(self.context, self.request)}
+ if 'table' in attributes:
+ attributes['table'].update(table_attrs)
+ else:
+ attributes['table'] = table_attrs
+ return attributes
+
+
+@adapter_config(context=(IReferenceTable, IPyAMSLayer, ReferenceTableContentsTable), provides=IValues)
+class ReferenceTableContentsValues(ContextRequestViewAdapter):
+ """Reference table contents values"""
+
+ @property
+ def values(self):
+ return self.context.values()
+
+
+@adapter_config(context=(IReferenceTable, IPyAMSLayer, ReferenceTableContentsTable), provides=IColumn)
+class ReferenceTableTrashColumn(TrashColumn):
+ """Reference table trash column"""
+
+ permission = MANAGE_SITE_ROOT_PERMISSION
+
+
+@pagelet_config(name='contents.html', context=IReferenceTable, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
+@implementer(IInnerPage)
+class ReferenceTableContentsView(AdminView, ContainerView):
+ """Reference table contents view"""
+
+ table_class = ReferenceTableContentsTable
+
+
+@adapter_config(context=(IReferenceTable, IAdminLayer, ReferenceTableContentsView), provides=IPageHeader)
+class ReferenceTableHeaderAdapter(DefaultPageHeaderAdapter):
+ """References table header adapter"""
+
+ title = _("References tables")
+
+ @property
+ def subtitle(self):
+ return II18n(self.context).query_attribute('title', request=self.request)
+
+ icon_class = 'fa fa-fw fa-table'
+
+
+@viewlet_config(name='properties.menu', context=IReferenceTable, layer=IAdminLayer,
+ manager=IPropertiesMenu, permission=VIEW_SYSTEM_PERMISSION, weight=20)
+class ReferenceTablePropertiesMenu(MenuItem):
+ """Reference table properties menu"""
+
+ label = _("Properties...")
+ icon_class = 'fa-edit'
+
+ url = 'properties.html'
+ modal_target = True
+
+
+@pagelet_config(name='properties.html', context=IReferenceTable, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
+class ReferenceTablePropertiesEditForm(AdminDialogEditForm):
+ """Reference table properties edit form"""
+
+ legend = _("Edit table properties")
+
+ fields = field.Fields(IReferenceTable).omit('__parent__', '__name__')
+ ajax_handler = 'properties.json'
+ edit_permission = MANAGE_SITE_ROOT_PERMISSION
+
+
+@view_config(name='properties.json', context=IReferenceTable, request_type=IPyAMSLayer,
+ permission=MANAGE_SITE_ROOT_PERMISSION, renderer='json', xhr=True)
+class ReferenceTablePropertiesAJAXEditForm(AJAXEditForm, ReferenceTablePropertiesEditForm):
+ """Reference table properties edit form, JSON renderer"""