--- a/src/pyams_content/component/paragraph/zmi/preview.py Wed Nov 07 18:22:19 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-#
-# 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'
-
-
-# import standard library
-
-# import interfaces
-from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \
- IParagraphRenderer
-from pyams_content.features.renderer.interfaces import ISharedContentRenderer
-from pyams_skin.layer import IPyAMSLayer
-
-# import packages
-from pyams_content.features.renderer.skin import BaseContentRenderer
-from pyams_utils.adapter import adapter_config
-
-
-@adapter_config(name='paragraphs-render', context=(IParagraphContainerTarget, IPyAMSLayer),
- provides=ISharedContentRenderer)
-class ParagraphsContainerRenderer(BaseContentRenderer):
- """Paragraphs container renderer"""
-
- weight = 10
-
- def __init__(self, context, request):
- super(ParagraphsContainerRenderer, self).__init__(context, request)
- paragraphs = [para for para in IParagraphContainer(self.context).values()
- if para.visible]
- registry = self.request.registry
- self.renderers = [registry.queryMultiAdapter((paragraph, self.request), IParagraphRenderer)
- for paragraph in paragraphs]
-
- def update(self):
- super(ParagraphsContainerRenderer, self).update()
- for renderer in self.renderers:
- if renderer is not None:
- renderer.language = self.language
- renderer.update()
-
- def render(self):
- result = ''
- for renderer in self.renderers:
- if renderer is not None:
- result += renderer.render()
- return result
--- a/src/pyams_content/features/footer/skin/__init__.py Wed Nov 07 18:22:19 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +0,0 @@
-#
-# 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'
-
-import logging
-logger = logging.getLogger('PyAMS (content)')
-
-from pyramid.decorator import reify
-from zope.interface import implementer
-
-from pyams_cache.beaker import get_cache
-from pyams_content.features.footer.interfaces import IFooterRenderer, IFooterSettings, IFooterTarget
-from pyams_content.features.renderer.interfaces import HIDDEN_RENDERER_NAME
-from pyams_content.features.renderer.skin import BaseContentRenderer
-from pyams_portal.interfaces import PREVIEW_MODE
-from pyams_portal.portlet import PORTLETS_CACHE_KEY, PORTLETS_CACHE_NAME, PORTLETS_CACHE_REGION
-from pyams_skin.layer import IPyAMSLayer
-from pyams_utils.adapter import adapter_config
-from pyams_utils.interfaces import ICacheKeyValue
-from pyams_utils.interfaces.url import DISPLAY_CONTEXT
-from pyams_utils.traversing import get_parent
-
-from pyams_content import _
-
-
-@implementer(IFooterRenderer)
-class BaseFooterRenderer(BaseContentRenderer):
- """Base footer renderer"""
-
- name = None
- settings_key = None
-
- @reify
- def settings_target(self):
- context = self.request.annotations.get(DISPLAY_CONTEXT)
- if context is None:
- context = self.context
- return get_parent(context, IFooterTarget)
-
- @reify
- def settings(self):
- if self.settings_interface is None:
- return None
- target = self.settings_target
- settings = IFooterSettings(target)
- while settings.inherit:
- settings = IFooterSettings(settings.parent)
- return settings.settings
-
- @reify
- def cache_key(self):
- return PORTLETS_CACHE_KEY.format(portlet=self.name,
- hostname=self.request.host,
- context=ICacheKeyValue(self.settings_target),
- lang=self.request.locale_name)
-
- def render(self):
- preview_mode = self.request.annotations.get(PREVIEW_MODE, False)
- if preview_mode:
- return super(BaseFooterRenderer, self).render()
- else:
- portlets_cache = get_cache(PORTLETS_CACHE_REGION, PORTLETS_CACHE_NAME)
- cache_key = self.cache_key
- if self.context is not self.request.context: # display shared content
- cache_key = '{0}::shared'.format(cache_key)
- try:
- result = portlets_cache.get_value(cache_key)
- logger.debug("Retrieving footer content from cache key {0}".format(cache_key))
- except KeyError:
- result = super(BaseFooterRenderer, self).render()
- portlets_cache.set_value(cache_key, result)
- logger.debug("Storing footer content to cache key {0}".format(cache_key))
- return result
-
-
-@adapter_config(name=HIDDEN_RENDERER_NAME, context=(IFooterTarget, IPyAMSLayer), provides=IFooterRenderer)
-class HiddenFooterRenderer(BaseFooterRenderer):
- """Hidden footer renderer"""
-
- name = HIDDEN_RENDERER_NAME
- label = _("Hidden footer")
- weight = -999
-
- def render(self):
- return ''
--- a/src/pyams_content/features/header/skin/__init__.py Wed Nov 07 18:22:19 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-#
-# 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'
-
-import logging
-logger = logging.getLogger('PyAMS (content)')
-
-from pyramid.decorator import reify
-from zope.interface import implementer
-
-from pyams_cache.beaker import get_cache
-from pyams_content.features.header.interfaces import IHeaderRenderer, IHeaderSettings, IHeaderTarget
-from pyams_content.features.header.skin.interfaces import IHeaderClass
-from pyams_content.features.renderer.interfaces import HIDDEN_RENDERER_NAME
-from pyams_content.features.renderer.skin import BaseContentRenderer
-from pyams_portal.interfaces import PREVIEW_MODE
-from pyams_portal.portlet import PORTLETS_CACHE_KEY, PORTLETS_CACHE_NAME, PORTLETS_CACHE_REGION
-from pyams_skin.layer import IPyAMSLayer
-from pyams_utils.adapter import adapter_config
-from pyams_utils.interfaces import ICacheKeyValue
-from pyams_utils.traversing import get_parent
-
-from pyams_content import _
-
-
-@implementer(IHeaderRenderer)
-class BaseHeaderRenderer(BaseContentRenderer):
- """Base header renderer"""
-
- name = None
- settings_key = None
-
- @reify
- def settings_target(self):
- context = self.request.display_context
- if context is None:
- context = self.context
- return get_parent(context, IHeaderTarget)
-
- @reify
- def settings(self):
- if self.settings_interface is None:
- return None
- target = self.settings_target
- settings = IHeaderSettings(target)
- while settings.inherit:
- settings = IHeaderSettings(settings.parent)
- return settings.settings
-
- @reify
- def cache_key(self):
- return PORTLETS_CACHE_KEY.format(portlet=self.name,
- hostname=self.request.host,
- context=ICacheKeyValue(self.settings_target),
- lang=self.request.locale_name)
-
- @property
- def main_header_class(self):
- request = self.request
- return request.registry.queryMultiAdapter((request.context, request), IHeaderClass, default='')
-
- def render(self):
- preview_mode = self.request.annotations.get(PREVIEW_MODE, False)
- if preview_mode:
- return super(BaseHeaderRenderer, self).render()
- else:
- portlets_cache = get_cache(PORTLETS_CACHE_REGION, PORTLETS_CACHE_NAME)
- cache_key = self.cache_key
- if self.context is not self.request.context: # display shared content
- cache_key = '{0}::shared'.format(cache_key)
- try:
- result = portlets_cache.get_value(cache_key)
- logger.debug("Retrieving header content from cache key {0}".format(cache_key))
- except KeyError:
- result = super(BaseHeaderRenderer, self).render()
- portlets_cache.set_value(cache_key, result)
- logger.debug("Storing header content to cache key {0}".format(cache_key))
- return result
-
-
-@adapter_config(name=HIDDEN_RENDERER_NAME, context=(IHeaderTarget, IPyAMSLayer), provides=IHeaderRenderer)
-class HiddenHeaderRenderer(BaseHeaderRenderer):
- """Hidden header renderer"""
-
- name = HIDDEN_RENDERER_NAME
- label = _("Hidden header")
- weight = -999
-
- def render(self):
- return ''
--- a/src/pyams_content/features/header/skin/interfaces.py Wed Nov 07 18:22:19 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-#
-# 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'
-
-
-# import standard library
-
-# import interfaces
-
-# import packages
-from zope.interface import Interface
-
-
-class IHeaderClass(Interface):
- """Custom header CSS class"""
--- a/src/pyams_content/features/renderer/interfaces.py Wed Nov 07 18:22:19 2018 +0100
+++ b/src/pyams_content/features/renderer/interfaces.py Wed Nov 07 19:00:06 2018 +0100
@@ -12,15 +12,9 @@
__docformat__ = 'restructuredtext'
-
-# import standard library
-
-# import interfaces
from zope.annotation import IAttributeAnnotatable
from zope.contentprovider.interfaces import IContentProvider
-
-# import packages
-from zope.interface import Interface, Attribute
+from zope.interface import Attribute, Interface
HIDDEN_RENDERER_NAME = 'hidden'
--- a/src/pyams_content/features/renderer/skin/__init__.py Wed Nov 07 18:22:19 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,70 +0,0 @@
-#
-# 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.decorator import reify
-from zope.interface import implementer
-
-from pyams_content import _
-from pyams_content.features.renderer.interfaces import HIDDEN_RENDERER_NAME, IContentRenderer, IRenderedContent, \
- IRendererSettings
-from pyams_i18n.interfaces import II18n
-from pyams_skin.layer import IPyAMSLayer
-from pyams_template.template import get_view_template
-from pyams_utils.adapter import ContextRequestAdapter, adapter_config
-
-
-@implementer(IContentRenderer)
-class BaseContentRenderer(ContextRequestAdapter):
- """Base content renderer"""
-
- label = None
- weight = 0
-
- settings_interface = None
- resources = ()
-
- language = None
- context_attrs = ()
- i18n_context_attrs = ()
-
- @reify
- def settings(self):
- if self.settings_interface is None:
- return None
- return IRendererSettings(self.context)
-
- def update(self):
- for resource in self.resources:
- resource.need()
- for attr in self.context_attrs:
- setattr(self, attr, getattr(self.context, attr, None))
- if self.i18n_context_attrs:
- i18n = II18n(self.context, None)
- if i18n is not None:
- for attr in self.i18n_context_attrs:
- setattr(self, attr, i18n.query_attribute(attr, lang=self.language, request=self.request))
-
- render = get_view_template()
-
-
-@adapter_config(name=HIDDEN_RENDERER_NAME, context=(IRenderedContent, IPyAMSLayer), provides=IContentRenderer)
-class HiddenContentRenderer(BaseContentRenderer):
- """Hidden content renderer"""
-
- label = _("Hidden content")
- weight = -999
-
- @staticmethod
- def render():
- return ''
--- a/src/pyams_content/shared/form/zmi/render.py Wed Nov 07 18:22:19 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +0,0 @@
-#
-# 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'
-
-
-# import standard library
-
-# import interfaces
-from pyams_content.features.renderer.interfaces import ISharedContentRenderer
-from pyams_content.shared.form.interfaces import IFormFieldContainerTarget, IFormFieldContainer
-from pyams_form.interfaces.form import IFormHelp
-from pyams_i18n.interfaces import II18n
-from pyams_skin.layer import IPyAMSLayer
-
-# import packages
-from pyams_content.features.renderer.skin import BaseContentRenderer
-from pyams_form.form import InnerAddForm
-from pyams_form.help import FormHelp
-from pyams_utils.adapter import adapter_config
-from z3c.form import field, button
-from zope.interface import Interface
-
-
-class FormFieldContainerDisplayForm(InnerAddForm):
- """Form fields container display form"""
-
- @property
- def legend(self):
- return II18n(self.context).query_attribute('user_title', request=self.request)
-
- @property
- def fields(self):
- fields = field.Fields(*IFormFieldContainer(self.context).get_fields())
- if self.context.use_captcha:
- # TODO: add captcha
- # fields += field.Fields(Captcha(title='', description='', required=True))
- pass
- return fields
-
- buttons = button.Buttons(Interface)
-
- def updateWidgets(self, prefix=None):
- super(FormFieldContainerDisplayForm, self).updateWidgets(prefix)
- for widget in self.widgets.values():
- field = IFormFieldContainer(self.context).get(widget.field.__name__)
- if field is not None:
- widget.placeholder = field.placeholder
-
-
-@adapter_config(context=(IFormFieldContainerTarget, IPyAMSLayer, FormFieldContainerDisplayForm),
- provides=IFormHelp)
-class FormFieldContainerDisplayFormHelp(FormHelp):
- """Form field container display form help adapter"""
-
- def __new__(cls, context, request, view):
- if not context.header:
- return None
- return FormHelp.__new__(cls)
-
- @property
- def message(self):
- return II18n(self.context).query_attribute('header', request=self.request)
-
- message_format = 'text'
-
-
-@adapter_config(name='form-render', context=(IFormFieldContainerTarget, IPyAMSLayer),
- provides=ISharedContentRenderer)
-class FormFieldContainerRenderer(BaseContentRenderer):
- """Form field container renderer"""
-
- weight = 20
- display_form = None
-
- def __init__(self, context, request):
- super(FormFieldContainerRenderer, self).__init__(context, request)
- self.display_form = FormFieldContainerDisplayForm(context, self.request)
-
- def update(self):
- super(FormFieldContainerRenderer, self).update()
- self.display_form.update()
-
- def render(self):
- return self.display_form.render()