Added thesaurus term views (used by glossary)
authorThierry Florac <thierry.florac@onf.fr>
Fri, 28 Dec 2018 10:48:14 +0100
changeset 314 422396b9b729
parent 313 42ad7cf59085
child 315 91448e576861
Added thesaurus term views (used by glossary)
src/pyams_default_theme/features/thesaurus/__init__.py
src/pyams_default_theme/features/thesaurus/templates/associated-terms.pt
src/pyams_default_theme/features/thesaurus/templates/footer.pt
src/pyams_default_theme/features/thesaurus/templates/header.pt
src/pyams_default_theme/features/thesaurus/templates/html.pt
src/pyams_default_theme/features/thesaurus/templates/illustration.pt
--- a/src/pyams_default_theme/features/thesaurus/__init__.py	Fri Dec 28 10:47:38 2018 +0100
+++ b/src/pyams_default_theme/features/thesaurus/__init__.py	Fri Dec 28 10:48:14 2018 +0100
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# 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,
@@ -12,49 +12,78 @@
 
 __docformat__ = 'restructuredtext'
 
-from pyramid.decorator import reify
-from pyramid.exceptions import NotFound
-from zope.interface import implementer
+from zope.interface import Interface
 
-from pyams_content.component.theme import ITagsManager
+from pyams_content.component.illustration import IIllustration
+from pyams_content.features.thesaurus import IThesaurusTermHTMLInfo
 from pyams_default_theme.features.thesaurus.interfaces import IThesaurusTermRenderer
-from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.interfaces import IDialog
+from pyams_i18n.interfaces import II18n
 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
+from pyams_thesaurus.interfaces.term import IThesaurusTerm
+from pyams_utils.adapter import adapter_config
+from pyams_viewlet.viewlet import ViewContentProvider
+
+
+@adapter_config(name='header',
+                context=(IThesaurusTerm, IPyAMSUserLayer, Interface),
+                provides=IThesaurusTermRenderer)
+@template_config(template='templates/header.pt', layer=IPyAMSUserLayer)
+class ThesaurusTermHeaderRenderer(ViewContentProvider):
+    """Thesaurus term header renderer"""
+
+    weight = 5
 
 
-@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"""
+@adapter_config(name='illustration',
+                context=(IThesaurusTerm, IPyAMSUserLayer, Interface),
+                provides=IThesaurusTermRenderer)
+@template_config(template='templates/illustration.pt', layer=IPyAMSUserLayer)
+class ThesaurusTermIllustrationRenderer(ViewContentProvider):
+    """Thesaurus term illustration renderer"""
+
+    weight = 10
+
+    illustration = None
 
-    dialog_class = 'modal-medium'
+    def update(self):
+        super(ThesaurusTermIllustrationRenderer, self).update()
+        self.illustration = IIllustration(self.context, None)
+
+
+@adapter_config(name='html',
+                context=(IThesaurusTerm, IPyAMSUserLayer, Interface),
+                provides=IThesaurusTermRenderer)
+@template_config(template='templates/html.pt', layer=IPyAMSUserLayer)
+class ThesaurusTermHtmlRenderer(ViewContentProvider):
+    """Thesaurus term HTML renderer"""
+
+    weight = 20
 
-    @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
+    html = None
+
+    def update(self):
+        super(ThesaurusTermHtmlRenderer, self).update()
+        info = IThesaurusTermHTMLInfo(self.context, None)
+        if info is not None:
+            self.html = II18n(info).query_attribute('description', request=self.request)
+
 
-    @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
+@adapter_config(name='associated-terms',
+                context=(IThesaurusTerm, IPyAMSUserLayer, Interface),
+                provides=IThesaurusTermRenderer)
+@template_config(template='templates/associated-terms.pt', layer=IPyAMSUserLayer)
+class ThesaurusTermAssociatedTermsRenderer(ViewContentProvider):
+    """Thesaurus term associated terms renderer"""
+
+    weight = 50
+
+
+@adapter_config(name='footer',
+                context=(IThesaurusTerm, IPyAMSUserLayer, Interface),
+                provides=IThesaurusTermRenderer)
+@template_config(template='templates/footer.pt', layer=IPyAMSUserLayer)
+class ThesaurusTermFooterRenderer(ViewContentProvider):
+    """Thesaurus term footer renderer"""
+
+    weight = 90
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/thesaurus/templates/associated-terms.pt	Fri Dec 28 10:48:14 2018 +0100
@@ -0,0 +1,35 @@
+<tal:var define="term view.context"
+		 i18n:domain="pyams_default_theme">
+	<div tal:condition="term.generic">
+		<strong i18n:translate="">Term family:</strong>
+		<span class="thesaurus-term"
+			  tal:omit-tag="term.status != 'published'">${term.generic.alt or term.generic.label}</span>
+	</div>
+	<div tal:condition="term.specifics">
+		<strong i18n:translate="">Specific terms:</strong>
+		<tal:loop repeat="specific term.specifics">
+			<span class="thesaurus-term"
+				  tal:omit-tag="specific.status != 'published'">${specific.alt or specific.label}</span><tal:if condition="not repeat.specific.end()">,</tal:if>
+		</tal:loop>
+	</div>
+	<div tal:condition="term.associations">
+		<strong i18n:translate="">Associated terms:</strong>
+		<tal:loop repeat="association term.associations">
+			<span class="thesaurus-term"
+				  tal:omit-tag="association.status != 'published'">${association.alt or association.label}</span><tal:if condition="not repeat.association.end()">,</tal:if>
+		</tal:loop>
+	</div>
+	<div tal:condition="term.used_for">
+		<strong i18n:translate="">Synonyms:</strong>
+		<tal:loop repeat="synonym term.used_for">
+			<span class="thesaurus-term"
+				  tal:omit-tag="synonym.status != 'published'">${synonym.alt or synonym.label}</span><tal:if condition="not repeat.synonym.end()">,</tal:if>
+		</tal:loop>
+	</div>
+	<div tal:condition="term.usage">
+		<strong i18n:translate="">See:</strong>
+		<span class="thesaurus-term"
+			  tal:omit-tag="term.usage != 'published'">${term.usage.alt or term.usage.label}</span>
+	</div>
+	<br />
+</tal:var>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/thesaurus/templates/footer.pt	Fri Dec 28 10:48:14 2018 +0100
@@ -0,0 +1,11 @@
+<div class="clearfix"></div>
+<div class="panel panel-info"
+	 i18n:domain="pyams_default_theme"
+	 tal:condition="context.note">
+	<div class="panel-heading">
+		<strong i18n:translate="">Note</strong>
+	</div>
+	<div class="panel-body">
+		${structure:tales:html(context.note, 'markdown')}
+	</div>
+</div>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/thesaurus/templates/header.pt	Fri Dec 28 10:48:14 2018 +0100
@@ -0,0 +1,3 @@
+<div tal:condition="context.definition">
+	${structure:tales:html(context.definition, 'markdown')}
+</div>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/thesaurus/templates/html.pt	Fri Dec 28 10:48:14 2018 +0100
@@ -0,0 +1,4 @@
+<tal:var define="html view.html"
+		 condition="html">
+	${structure:tales:html(view.html, 'oid_to_href;glossary')}
+</tal:var>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/thesaurus/templates/illustration.pt	Fri Dec 28 10:48:14 2018 +0100
@@ -0,0 +1,18 @@
+<div class="illustration pull-right col-xs-12 col-sm-6 col-md-6 col-lg-5 margin-10"
+	 tal:define="illustration view.illustration"
+	 tal:condition="illustration and illustration.data">
+	<a data-toggle="lightbox"
+	   data-type="image"
+	   data-title="${i18n:illustration.title}"
+	   data-footer="${illustration.author}"
+	   tal:define="image i18n:illustration.data;
+				   thumbnails tales:thumbnails(image);
+				   target thumbnails.get_thumbnail('800x600');
+				   alt i18n:illustration.alt_title;"
+	   href="${tales:absolute_url(target)}">
+		<tal:if condition="image">
+			${structure:tales:picture(image, lg_width=5, md_width=6, sm_width=6, alt=alt_title)}
+		</tal:if>
+	</a>
+	<div class="author">${i18n:illustration.title}</div>
+</div>