# HG changeset patch # User Thierry Florac # Date 1545990494 -3600 # Node ID 422396b9b729eb61e034fee07d92f899b5b1aaf6 # Parent 42ad7cf59085e3ebbc16b9bb60c4f71bb4257a16 Added thesaurus term views (used by glossary) diff -r 42ad7cf59085 -r 422396b9b729 src/pyams_default_theme/features/thesaurus/__init__.py --- 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 +# Copyright (c) 2008-2018 Thierry Florac # 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 diff -r 42ad7cf59085 -r 422396b9b729 src/pyams_default_theme/features/thesaurus/templates/associated-terms.pt --- /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 @@ + +
+ Term family: + ${term.generic.alt or term.generic.label} +
+
+ Specific terms: + + ${specific.alt or specific.label}, + +
+
+ Associated terms: + + ${association.alt or association.label}, + +
+
+ Synonyms: + + ${synonym.alt or synonym.label}, + +
+
+ See: + ${term.usage.alt or term.usage.label} +
+
+
\ No newline at end of file diff -r 42ad7cf59085 -r 422396b9b729 src/pyams_default_theme/features/thesaurus/templates/footer.pt --- /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 @@ +
+
+
+ Note +
+
+ ${structure:tales:html(context.note, 'markdown')} +
+
\ No newline at end of file diff -r 42ad7cf59085 -r 422396b9b729 src/pyams_default_theme/features/thesaurus/templates/header.pt --- /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 @@ +
+ ${structure:tales:html(context.definition, 'markdown')} +
\ No newline at end of file diff -r 42ad7cf59085 -r 422396b9b729 src/pyams_default_theme/features/thesaurus/templates/html.pt --- /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 @@ + + ${structure:tales:html(view.html, 'oid_to_href;glossary')} + \ No newline at end of file diff -r 42ad7cf59085 -r 422396b9b729 src/pyams_default_theme/features/thesaurus/templates/illustration.pt --- /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 @@ +