# HG changeset patch # User Thierry Florac # Date 1541609932 -3600 # Node ID 50612c78ed2ad67205bd9835d7cb578bfef6ba91 # Parent 2375abafdeb1a8e64b7f83fd55298ff5a59ae45b Moved skin features to PyAMS default theme diff -r 2375abafdeb1 -r 50612c78ed2a src/pyams_content/shared/common/skin/__init__.py --- a/src/pyams_content/shared/common/skin/__init__.py Wed Nov 07 17:49:35 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -# -# Copyright (c) 2008-2018 Thierry Florac -# 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 pyams_content.shared.common import ISharedContent, IWfSharedContent -from pyams_content.shared.site import ISiteElementNavigation -from pyams_content.shared.site.interfaces import IContentSummaryInfo -from pyams_i18n.interfaces import II18n -from pyams_skin.layer import IPyAMSUserLayer -from pyams_utils.adapter import ContextRequestAdapter, adapter_config -from pyams_workflow.interfaces import IWorkflowPublicationInfo - -from pyams_content import _ - - -@adapter_config(context=(ISharedContent, IPyAMSUserLayer), provides=ISiteElementNavigation) -class SharedContentNavigationAdapter(ContextRequestAdapter): - """Shared content navigation adapter""" - - @property - def visible(self): - version = self.context.published_version - if version is not None: - return IWorkflowPublicationInfo(version).is_visible(self.request) - - -@adapter_config(context=(ISharedContent, IPyAMSUserLayer), provides=IContentSummaryInfo) -def shared_content_summary_adapter(context, request): - """Shared content summary adapter""" - version = context.published_version - if version is not None: - return request.registry.queryMultiAdapter((version, request), IContentSummaryInfo) - - -@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=IContentSummaryInfo) -class WfSharedContentSummaryInfo(ContextRequestAdapter): - """Shared content summary info adapter""" - - @property - def title(self): - return II18n(self.context).query_attribute('title', request=self.request) - - @property - def header(self): - return II18n(self.context).query_attribute('header', request=self.request) - - @property - def button_title(self): - return _("Consult content") diff -r 2375abafdeb1 -r 50612c78ed2a src/pyams_content/shared/common/skin/oid.py --- a/src/pyams_content/shared/common/skin/oid.py Wed Nov 07 17:49:35 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -# -# Copyright (c) 2008-2018 Thierry Florac -# 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' - - -# import standard library - -# import interfaces -from pyams_sequence.interfaces import ISequentialIntIds -from pyams_skin.layer import IPyAMSUserLayer -from pyams_utils.interfaces.url import DISPLAY_CONTEXT -from pyams_workflow.interfaces import IWorkflow, IWorkflowVersions -from zope.traversing.interfaces import ITraversable - -# import packages -from pyams_sequence.reference import get_reference_target -from pyams_utils.adapter import adapter_config, ContextRequestAdapter -from pyams_utils.registry import get_utility -from pyramid.exceptions import NotFound -from zope.interface import Interface - - -@adapter_config(name='oid', context=(Interface, IPyAMSUserLayer), provides=ITraversable) -class OidTraverser(ContextRequestAdapter): - """++oid++ traverser""" - - def traverse(self, name, furtherpath=None): - if not name: - raise NotFound() - if '::' in name: - oid, label = name.split('::', 1) - else: - oid = name - sequence = get_utility(ISequentialIntIds) - reference = sequence.get_full_oid(oid) - target = get_reference_target(reference) - if target is not None: - workflow = IWorkflow(target, None) - if workflow is not None: - versions = IWorkflowVersions(target).get_versions(workflow.published_states, sort=True) - if versions: - target = versions[-1] - if target is not None: - self.request.annotations[DISPLAY_CONTEXT] = self.context - return target - raise NotFound() diff -r 2375abafdeb1 -r 50612c78ed2a src/pyams_content/shared/common/skin/opengraph.py --- a/src/pyams_content/shared/common/skin/opengraph.py Wed Nov 07 17:49:35 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -# -# Copyright (c) 2008-2018 Thierry Florac -# 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' - - -# import standard library - -# import interfaces -from pyams_content.component.illustration import IIllustration, IIllustrationTarget -from pyams_content.component.theme.interfaces import ITagsInfo -from pyams_content.shared.common.interfaces import IWfSharedContent -from pyams_i18n.interfaces import II18n, INegotiator, II18nManager -from pyams_file.interfaces import IThumbnails -from pyams_skin.interfaces.configuration import IConfiguration -from pyams_skin.interfaces.metas import IHTMLContentMetas -from pyams_skin.layer import IPyAMSUserLayer -from pyams_workflow.interfaces import IWorkflowPublicationInfo -from zope.dublincore.interfaces import IZopeDublinCore - -# import packages -from pyams_skin.metas import PropertyMeta -from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter -from pyams_utils.registry import get_utility -from pyams_utils.traversing import get_parent -from pyams_utils.url import canonical_url, absolute_url -from zope.interface import Interface - - -@adapter_config(name='opengraph', context=(IWfSharedContent, IPyAMSUserLayer, Interface), provides=IHTMLContentMetas) -class OpengraphSharedContentMetasAdapter(ContextRequestViewAdapter): - """Opengraph shared content metas adapter""" - - order = 15 - - def get_metas(self): - context = self.context - i18n = II18n(context) - request = self.request - negotiator = get_utility(INegotiator) - lang = negotiator.server_language - # main properties - yield PropertyMeta('og:title', i18n.query_attribute('title', lang=lang, request=request)) - yield PropertyMeta('og:description', i18n.query_attribute('description', lang=lang, request=request) or '') - yield PropertyMeta('og:type', 'article') - # workflow informations - dc = IZopeDublinCore(context, None) - if (dc is not None) and dc.modified: - yield PropertyMeta('article:modified_time', dc.modified.isoformat()) - pub_info = IWorkflowPublicationInfo(context, None) - if pub_info is not None: - if pub_info.first_publication_date: - yield PropertyMeta('article:published_time', pub_info.first_publication_date.isoformat()) - if pub_info.publication_expiration_date: - yield PropertyMeta('article:expiration_time', pub_info.publication_expiration_date.isoformat()) - # tags - tags = ITagsInfo(context, None) - if tags is not None: - for tag in tags.tags or (): - yield PropertyMeta('article:tag', tag.label) - # URL and site name - yield PropertyMeta('og:url', canonical_url(context, request)) - configuration = IConfiguration(request.root) - yield PropertyMeta('og:site_name', configuration.title) - # illustration properties - registry = request.registry - illustration = None - target = context - while target is not None: - illustration = registry.queryAdapter(target, IIllustration, name='link') - if (illustration is None) or (not illustration.has_data()): - illustration = registry.queryAdapter(target, IIllustration) - if (illustration is not None) and illustration.has_data(): - break - target = get_parent(target, IIllustrationTarget, allow_context=False) - if (target is not None) and (illustration is not None): - data = II18n(illustration).query_attribute('data', lang=lang, request=request) - thumbnail = IThumbnails(data).get_thumbnail('800x600') - yield PropertyMeta('og:image:url', absolute_url(thumbnail, self.request)) - yield PropertyMeta('og:image:type', thumbnail.content_type) - image_size = thumbnail.image_size - yield PropertyMeta('og:image:width', image_size[0]) - yield PropertyMeta('og:image:height', image_size[1]) - yield PropertyMeta('og:image:alt', II18n(illustration).query_attribute('alt_title', lang=lang, - request=request)) - # locales properties - yield PropertyMeta('og:locale', lang) - for lang in II18nManager(context).languages or (): - yield PropertyMeta('og:locale:alternate', lang) diff -r 2375abafdeb1 -r 50612c78ed2a src/pyams_content/shared/common/skin/url.py --- a/src/pyams_content/shared/common/skin/url.py Wed Nov 07 17:49:35 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -# -# Copyright (c) 2008-2018 Thierry Florac -# 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 pyams_content.shared.common import ISharedContent, IWfSharedContent -from pyams_sequence.interfaces import ISequentialIdInfo -from pyams_skin.layer import IPyAMSUserLayer -from pyams_utils.adapter import ContextRequestAdapter, adapter_config -from pyams_utils.interfaces.url import IRelativeURL -from pyams_utils.url import absolute_url, relative_url - - -@adapter_config(context=(ISharedContent, IPyAMSUserLayer), provides=IRelativeURL) -class SharedContentRelativeURLAdapter(ContextRequestAdapter): - """Shared content relative URL adapter""" - - def get_url(self, display_context=None, view_name=None, query=None): - version = self.context.published_version - if version is not None: - return relative_url(version, self.request, display_context, view_name, query) - - -@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=IRelativeURL) -class WfSharedContentRelativeUrlAdapter(ContextRequestAdapter): - """Workflow managed shared content relative URL adapter""" - - def get_url(self, display_context=None, view_name=None, query=None): - return absolute_url(display_context, self.request, - '++oid++{0}::{1}{2}{3}'.format( - ISequentialIdInfo(self.context).get_base_oid().strip(), - self.context.content_url, - '/{}'.format(view_name) if view_name else '.html', - '?{}'.format(query) if query else ''))