Added thesaurus term HTML description
authorThierry Florac <thierry.florac@onf.fr>
Tue, 27 Nov 2018 17:11:57 +0100
changeset 1132 f1276d7bc4ce
parent 1131 64747fd623b3
child 1133 52a1a1db5ec5
Added thesaurus term HTML description
src/pyams_content/features/thesaurus/__init__.py
src/pyams_content/features/thesaurus/interfaces.py
src/pyams_content/features/thesaurus/zmi/__init__.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/features/thesaurus/__init__.py	Tue Nov 27 17:11:57 2018 +0100
@@ -0,0 +1,53 @@
+#
+# 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'
+
+from persistent import Persistent
+from zope.container.contained import Contained
+from zope.interface import implementer
+from zope.schema.fieldproperty import FieldProperty
+
+from pyams_content.features.thesaurus.interfaces import IThesaurusTermHTMLInfo, IThesaurusTermHTMLTarget, \
+    THESAURUS_TERM_HTML_INFO_KEY
+from pyams_thesaurus.interfaces.extension import IThesaurusTermExtension
+from pyams_utils.adapter import adapter_config, get_annotation_adapter
+from pyams_utils.factory import factory_config
+from pyams_utils.registry import utility_config
+
+from pyams_content import _
+
+
+@factory_config(provided=IThesaurusTermHTMLInfo)
+@implementer(IThesaurusTermHTMLInfo)
+class ThesaurusTermHTMLInfo(Persistent, Contained):
+    """Thesaurus term HTML description"""
+
+    description = FieldProperty(IThesaurusTermHTMLInfo['description'])
+
+
+@adapter_config(context=IThesaurusTermHTMLTarget, provides=IThesaurusTermHTMLInfo)
+def thesaurus_term_html_description_factory(context):
+    """Thesaurus term HTML description factory"""
+    return get_annotation_adapter(context, THESAURUS_TERM_HTML_INFO_KEY, IThesaurusTermHTMLInfo)
+
+
+@utility_config(name='html', provides=IThesaurusTermExtension)
+class HTMLThesaurusExtension(object):
+    """HTML description thesaurus extension"""
+
+    label = _("Rich text description")
+
+    target_interface = IThesaurusTermHTMLTarget
+    target_view = 'html-description.html'
+
+    icon = '<i class="fa fa-fw fa-font"></i>'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/features/thesaurus/interfaces.py	Tue Nov 27 17:11:57 2018 +0100
@@ -0,0 +1,33 @@
+#
+# 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'
+
+from zope.interface import Interface
+
+from pyams_i18n.schema import I18nHTMLField
+
+from pyams_content import _
+
+
+THESAURUS_TERM_HTML_INFO_KEY = 'pyams_content.term.html_info'
+
+
+class IThesaurusTermHTMLInfo(Interface):
+    """Thesaurus term HTML info"""
+
+    description = I18nHTMLField(title=_("HTML content"),
+                                required=False)
+
+
+class IThesaurusTermHTMLTarget(Interface):
+    """Thesaurus term HTML description target"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/features/thesaurus/zmi/__init__.py	Tue Nov 27 17:11:57 2018 +0100
@@ -0,0 +1,45 @@
+#
+# 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'
+
+from z3c.form import field
+
+from pyams_content.features.thesaurus import IThesaurusTermHTMLTarget
+from pyams_content.features.thesaurus.interfaces import IThesaurusTermHTMLInfo
+from pyams_form.form import ajax_config
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_skin.layer import IPyAMSLayer
+from pyams_thesaurus.interfaces import MANAGE_THESAURUS_CONTENT_PERMISSION
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+from pyams_zmi.form import AdminDialogEditForm
+
+from pyams_content import _
+
+
+@pagelet_config(name='html-description.html', context=IThesaurusTermHTMLTarget, layer=IPyAMSLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+@ajax_config(name='html-description.json', context=IThesaurusTermHTMLTarget, layer=IPyAMSLayer)
+class ThesaurusTermHTMLDescriptionPropertiesEditForm(AdminDialogEditForm):
+    """Thesaurus term HTML description properties edit form"""
+
+    prefix = 'html_description_form.'
+
+    legend = _("Edit rich text description")
+    dialog_class = 'modal-max'
+    icon_css_class = 'fa fa-fw fa-font'
+
+    fields = field.Fields(IThesaurusTermHTMLInfo)
+    edit_permission = MANAGE_THESAURUS_CONTENT_PERMISSION
+
+    def getContent(self):
+        return IThesaurusTermHTMLInfo(self.context)