Added thesaurus term's view
authorThierry Florac <tflorac@ulthar.net>
Fri, 14 Dec 2018 18:30:00 +0100
changeset 292 1d2d4bb25fbc
parent 291 1808386adb8e
child 293 b2f7d60562ba
Added thesaurus term's view
src/pyams_default_theme/features/thesaurus/__init__.py
src/pyams_default_theme/features/thesaurus/interfaces.py
src/pyams_default_theme/features/thesaurus/templates/glossary.pt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/thesaurus/__init__.py	Fri Dec 14 18:30:00 2018 +0100
@@ -0,0 +1,60 @@
+#
+# 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'
+
+from pyramid.decorator import reify
+from pyramid.exceptions import NotFound
+from zope.interface import implementer
+
+from pyams_content.component.theme import ITagsManager
+from pyams_default_theme.features.thesaurus.interfaces import IThesaurusTermRenderer
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_skin.interfaces import IDialog
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_template.template import template_config
+from pyams_thesaurus.interfaces.thesaurus import IThesaurus
+from pyams_utils.interfaces import VIEW_PERMISSION
+from pyams_utils.registry import query_utility
+
+
+@pagelet_config(name='get-glossary-term.html', layer=IPyAMSUserLayer, permission=VIEW_PERMISSION)
+@template_config(template='templates/glossary.pt', layer=IPyAMSUserLayer)
+@implementer(IDialog)
+class GlossaryTermView(object):
+    """Glossary term view"""
+
+    dialog_class = 'modal-medium'
+
+    @reify
+    def term(self):
+        tags_manager = ITagsManager(self.request.root)
+        if not tags_manager.enable_glossary:
+            raise NotFound("Glossary access is not defined.")
+        term = self.request.params.get('term')
+        if not term:
+            raise NotFound("No glossary term defined.")
+        thesaurus = query_utility(IThesaurus, name=tags_manager.glossary_thesaurus_name)
+        if thesaurus is None:
+            raise NotFound("Glossary thesaurus can't be found.")
+        term = thesaurus.terms.get(term)
+        if term is None:
+            raise NotFound("Can't find specified term.")
+        return term
+
+    @property
+    def renderers(self):
+        registry = self.request.registry
+        for name, renderer in sorted(registry.getAdapters((self.term, self.request), IThesaurusTermRenderer),
+                                     key=lambda x: x.weight):
+            renderer.update()
+            yield renderer
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/thesaurus/interfaces.py	Fri Dec 14 18:30:00 2018 +0100
@@ -0,0 +1,22 @@
+#
+# 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.contentprovider.interfaces import IContentProvider
+from zope.interface import Attribute
+
+
+class IThesaurusTermRenderer(IContentProvider):
+    """Thesaurus term renderer"""
+
+    weight = Attribute("Adapter weight used for sorting")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/thesaurus/templates/glossary.pt	Fri Dec 14 18:30:00 2018 +0100
@@ -0,0 +1,29 @@
+<div class="modal-content" i18n:domain="pyams_default_theme"
+	 tal:define="term view.term">
+	<div class="modal-header">
+		<button type="button" class="close"
+				data-dismiss="modal" aria-hidden="true">
+			<i class="fa fa-fw fa-times-circle"></i>
+		</button>
+		<h3 class="modal-title"></h3>
+	</div>
+	<div class="modal-body no-padding">
+		<div class="modal-viewport">
+			<fieldset>
+				<legend>
+					<i></i>
+					${term.alt or term.label}
+				</legend>
+				<div class="clearfix"></div>
+				<tal:loop repeat="renderer view.renderers">
+					${structure:renderer.render()}
+				</tal:loop>
+			</fieldset>
+		</div>
+		<footer>
+			<button type="button" data-dismiss="modal"
+					class="btn close-widget closebutton-field"
+					value="Cancel" i18n:translate="">Close</button>
+		</footer>
+	</div>
+</div>