Updated breadcrumbs viewlet
authorThierry Florac <thierry.florac@onf.fr>
Mon, 12 Nov 2018 11:37:45 +0100
changeset 213 13da52c39ccc
parent 212 7a9c4cd8c1dd
child 214 03d87dee4723
Updated breadcrumbs viewlet
src/pyams_default_theme/viewlet/breadcrumb/__init__.py
src/pyams_default_theme/viewlet/breadcrumb/breadcrumbs.pt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/viewlet/breadcrumb/__init__.py	Mon Nov 12 11:37:45 2018 +0100
@@ -0,0 +1,47 @@
+#
+# 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 pyramid.location import lineage
+from zope.interface import Interface
+
+from pyams_skin.interfaces.viewlet import IBreadcrumbItem
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_skin.viewlet.breadcrumb import BreadcrumbsContentProvider as BaseBreadcrumbsContentProvider
+from pyams_template.template import template_config
+from pyams_utils.interfaces.url import DISPLAY_CONTEXT
+from pyams_viewlet.viewlet import contentprovider_config
+
+
+@contentprovider_config(name='pyams.breadcrumbs', layer=IPyAMSUserLayer, view=Interface)
+@template_config(template='breadcrumbs.pt', layer=IPyAMSUserLayer)
+class BreadcrumbsContentProvider(BaseBreadcrumbsContentProvider):
+    """Breadcrumbs content provider"""
+
+    @property
+    def items(self):
+        source = None
+        registry = self.request.registry
+        if source is None:
+            source = self.request.annotations.get(DISPLAY_CONTEXT)
+            if source is None:
+                source = self.request.context
+        if source is not None:
+            for context in reversed(tuple(lineage(source))):
+                item = registry.queryMultiAdapter((context, self.request, self.view), IBreadcrumbItem)
+                if item is None:
+                    item = registry.queryMultiAdapter((context, self.request), IBreadcrumbItem)
+                    if item is None:
+                        item = registry.queryAdapter(context, IBreadcrumbItem)
+                if item is not None:
+                    yield item
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/viewlet/breadcrumb/breadcrumbs.pt	Mon Nov 12 11:37:45 2018 +0100
@@ -0,0 +1,6 @@
+<ol class="breadcrumb">
+	<li tal:repeat="item view.items">
+		<a class="${'active' if repeat.item.end else None}"
+		   href="${item.url}">${item.label}</a>
+	</li>
+</ol>
\ No newline at end of file