# HG changeset patch # User Damien Correia # Date 1527240497 -7200 # Node ID b438528e5bb394cfc3292701afb6cfb200a13250 # Parent 26a58877d1aabdacd13d52ea5fca37c708c612a0# Parent a78ade534b97eb7f11c380c2463a5b4544b6bc8a merge default diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/association/interfaces/__init__.py --- a/src/pyams_content/component/association/interfaces/__init__.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/association/interfaces/__init__.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,6 @@ # import interfaces from pyams_content.component.paragraph.interfaces import IBaseParagraph -from pyams_content.features.renderer import IRenderedContent from zope.annotation.interfaces import IAttributeAnnotatable from zope.container.interfaces import IOrderedContainer @@ -87,7 +86,7 @@ ASSOCIATION_PARAGRAPH_RENDERERS = 'PyAMS.associations.renderers' -class IAssociationParagraph(IRenderedContent, IBaseParagraph): +class IAssociationParagraph(IBaseParagraph): """Associations paragraph interface""" renderer = Choice(title=_("Associations template"), diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/association/paragraph.py --- a/src/pyams_content/component/association/paragraph.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/association/paragraph.py Fri May 25 11:28:17 2018 +0200 @@ -22,26 +22,26 @@ from pyams_content.component.links.interfaces import ILinkContainerTarget from pyams_content.component.paragraph.interfaces import IParagraphFactory from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE -from pyams_content.features.renderer.interfaces import IContentRenderer from pyams_i18n.interfaces import II18n, II18nManager, INegotiator # import packages from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory -from pyams_content.features.renderer import RenderedContentMixin +from pyams_content.features.renderer import RenderersVocabulary from pyams_utils.adapter import adapter_config +from pyams_utils.factory import factory_config from pyams_utils.registry import utility_config, get_utility from pyams_utils.request import check_request from pyams_utils.traversing import get_parent from pyams_utils.vocabulary import vocabulary_config from zope.interface import implementer from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pyams_content import _ @implementer(IAssociationParagraph, IExtFileContainerTarget, ILinkContainerTarget) -class AssociationParagraph(RenderedContentMixin, BaseParagraph): +@factory_config(provided=IAssociationParagraph) +class AssociationParagraph(BaseParagraph): """Associations paragraph""" icon_class = 'fa-link' @@ -91,16 +91,7 @@ @vocabulary_config(name=ASSOCIATION_PARAGRAPH_RENDERERS) -class AssociationParagraphRendererVocabulary(SimpleVocabulary): +class AssociationParagraphRendererVocabulary(RenderersVocabulary): """Associations paragraph renderers vocabulary""" - def __init__(self, context=None): - request = check_request() - translate = request.localizer.translate - registry = request.registry - if not IAssociationParagraph.providedBy(context): - context = AssociationParagraph() - terms = [SimpleTerm(name, title=translate(adapter.label)) - for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), - key=lambda x: x[1].weight)] - super(AssociationParagraphRendererVocabulary, self).__init__(terms) + content_interface = IAssociationParagraph diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/association/zmi/paragraph.py --- a/src/pyams_content/component/association/zmi/paragraph.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/association/zmi/paragraph.py Fri May 25 11:28:17 2018 +0200 @@ -18,8 +18,7 @@ # import interfaces from pyams_content.component.association.interfaces import IAssociationParagraph, ASSOCIATION_PARAGRAPH_TYPE from pyams_content.component.association.zmi.interfaces import IAssociationsParentForm -from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ - IParagraphRenderer +from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphContainerView from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION from pyams_content.shared.common.interfaces import IWfSharedContent @@ -33,7 +32,6 @@ from pyams_content.component.association.paragraph import AssociationParagraph from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \ BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, IParagraphEditFormButtons -from pyams_content.features.renderer.zmi import BaseRenderedContentRenderer from pyams_content.features.renderer.zmi.widget import RendererFieldWidget from pyams_pagelet.pagelet import pagelet_config from pyams_skin.event import get_json_widget_refresh_event @@ -141,12 +139,3 @@ AssociationParagraphInnerEditForm, 'renderer')) return output - - -# -# Association paragraph renderer -# - -@adapter_config(context=(IAssociationParagraph, IPyAMSLayer), provides=IParagraphRenderer) -class AssociationParagraphRenderer(BaseRenderedContentRenderer): - """Association paragraph renderer""" diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/gallery/__init__.py --- a/src/pyams_content/component/gallery/__init__.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/gallery/__init__.py Fri May 25 11:28:17 2018 +0200 @@ -23,7 +23,6 @@ from pyams_content.shared.common.interfaces import IWfSharedContent from pyams_form.interfaces.form import IFormContextPermissionChecker from pyams_i18n.interfaces import II18n -from zope.annotation.interfaces import IAnnotations from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent from zope.location.interfaces import ISublocations from zope.traversing.interfaces import ITraversable @@ -31,10 +30,10 @@ # import packages from pyams_catalog.utils import index_object from pyams_content.features.checker import BaseContentChecker -from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer -from pyams_utils.adapter import adapter_config, ContextAdapter +from pyams_content.features.renderer import RenderedContentMixin, RenderersVocabulary +from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter +from pyams_utils.factory import factory_config from pyams_utils.container import BTreeOrderedContainer -from pyams_utils.request import check_request from pyams_utils.traversing import get_parent from pyams_utils.vocabulary import vocabulary_config from pyramid.events import subscriber @@ -43,7 +42,6 @@ from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent from zope.location import locate from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pyams_content import _ @@ -53,7 +51,8 @@ # @implementer(IGallery) -class Gallery(BTreeOrderedContainer, RenderedContentMixin): +@factory_config(provided=IBaseGallery) +class Gallery(RenderedContentMixin, BTreeOrderedContainer): """Gallery persistent class""" title = FieldProperty(IGallery['title']) @@ -80,13 +79,7 @@ @adapter_config(context=IGalleryTarget, provides=IGallery) def gallery_factory(target): """Galleries container factory""" - annotations = IAnnotations(target) - gallery = annotations.get(GALLERY_CONTAINER_KEY) - if gallery is None: - gallery = annotations[GALLERY_CONTAINER_KEY] = Gallery() - get_current_registry().notify(ObjectCreatedEvent(gallery)) - locate(gallery, target, '++gallery++') - return gallery + return get_annotation_adapter(target, GALLERY_CONTAINER_KEY, Gallery, name='++gallery++') @adapter_config(name='gallery', context=IGalleryTarget, provides=ITraversable) @@ -183,16 +176,7 @@ @vocabulary_config(name=GALLERY_RENDERERS) -class GalleryRendererVocabulary(SimpleVocabulary): +class GalleryRendererVocabulary(RenderersVocabulary): """Gallery renderers vocabulary""" - def __init__(self, context=None): - request = check_request() - translate = request.localizer.translate - registry = request.registry - if not IBaseGallery.providedBy(context): - context = Gallery() - terms = [SimpleTerm(name, title=translate(adapter.label)) - for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), - key=lambda x: x[1].weight)] - super(GalleryRendererVocabulary, self).__init__(terms) + content_interface = IBaseGallery diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/gallery/zmi/paragraph.py --- a/src/pyams_content/component/gallery/zmi/paragraph.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/gallery/zmi/paragraph.py Fri May 25 11:28:17 2018 +0200 @@ -18,8 +18,7 @@ # import interfaces from pyams_content.component.gallery.interfaces import IGalleryParagraph, IBaseGallery, GALLERY_PARAGRAPH_TYPE from pyams_content.component.gallery.zmi.interfaces import IGalleryContentsView -from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ - IParagraphRenderer +from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphContainerView from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION from pyams_form.interfaces.form import IInnerForm, IInnerSubForm @@ -33,7 +32,6 @@ from pyams_content.component.gallery.paragraph import Gallery from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \ BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, get_json_paragraph_refresh_event, IParagraphEditFormButtons -from pyams_content.features.renderer.zmi import BaseRenderedContentRenderer from pyams_content.features.renderer.zmi.widget import RendererFieldWidget from pyams_content.shared.common.zmi import WfSharedContentPermissionMixin from pyams_pagelet.pagelet import pagelet_config @@ -178,12 +176,3 @@ url = 'add-media.html' modal_target = True stop_propagation = True - - -# -# Gallery paragraph renderer -# - -@adapter_config(context=(IGalleryParagraph, IPyAMSLayer), provides=IParagraphRenderer) -class GalleryParagraphRenderer(BaseRenderedContentRenderer): - """Gallery paragraph renderer""" diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/illustration/__init__.py --- a/src/pyams_content/component/illustration/__init__.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/illustration/__init__.py Fri May 25 11:28:17 2018 +0200 @@ -29,9 +29,10 @@ # import packages from persistent import Persistent from pyams_content.features.checker import BaseContentChecker -from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer +from pyams_content.features.renderer import RenderedContentMixin, RenderersVocabulary from pyams_i18n.property import I18nFileProperty from pyams_utils.adapter import adapter_config, ContextAdapter +from pyams_utils.factory import factory_config from pyams_utils.registry import query_utility, get_utility from pyams_utils.request import check_request from pyams_utils.traversing import get_parent @@ -43,13 +44,13 @@ from zope.lifecycleevent import ObjectCreatedEvent, ObjectAddedEvent from zope.location import locate from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pyams_content import _ @implementer(IIllustration) -class Illustration(Persistent, Contained, RenderedContentMixin): +@factory_config(provided=IIllustration) +class Illustration(RenderedContentMixin, Persistent, Contained): """Illustration persistent class""" _data = I18nFileProperty(IIllustration['data']) @@ -178,16 +179,7 @@ @vocabulary_config(name=ILLUSTRATION_RENDERERS) -class IllustrationRendererVocabulary(SimpleVocabulary): +class IllustrationRendererVocabulary(RenderersVocabulary): """Illustration renderers vocabulary""" - def __init__(self, context=None): - request = check_request() - translate = request.localizer.translate - registry = request.registry - if not IIllustration.providedBy(context): - context = Illustration() - terms = [SimpleTerm(name, title=translate(adapter.label)) - for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), - key=lambda x: x[1].weight)] - super(IllustrationRendererVocabulary, self).__init__(terms) + content_interface = IIllustration diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/illustration/zmi/paragraph.py --- a/src/pyams_content/component/illustration/zmi/paragraph.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/illustration/zmi/paragraph.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,7 @@ # import interfaces from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, \ - IParagraphContainer, IParagraphRenderer + IParagraphContainer from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationParagraph, \ ILLUSTRATION_PARAGRAPH_TYPE from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphContainerView @@ -32,7 +32,6 @@ from pyams_content.component.illustration.paragraph import Illustration from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \ BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, get_json_paragraph_refresh_event, IParagraphEditFormButtons -from pyams_content.features.renderer.zmi import BaseRenderedContentRenderer from pyams_content.features.renderer.zmi.widget import RendererFieldWidget from pyams_pagelet.pagelet import pagelet_config from pyams_skin.event import get_json_form_refresh_event @@ -162,12 +161,3 @@ output.setdefault('events', []).append(get_json_form_refresh_event(self.context, self.request, IllustrationInnerEditForm)) return output - - -# -# Illustration renderer -# - -@adapter_config(context=(IIllustrationParagraph, IPyAMSLayer), provides=IParagraphRenderer) -class IllustrationRenderer(BaseRenderedContentRenderer): - """Illustration renderer""" diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/__init__.py --- a/src/pyams_content/component/paragraph/__init__.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/__init__.py Fri May 25 11:28:17 2018 +0200 @@ -18,6 +18,7 @@ # import interfaces from pyams_content.component.paragraph.interfaces import IBaseParagraph, IParagraphFactory, IParagraphContainerTarget, \ IParagraphContainer, IParagraphFactorySettings +from pyams_content.features.preview.interfaces import IPreviewTarget from pyams_content.shared.common.interfaces import IWfSharedContent from pyams_form.interfaces.form import IFormContextPermissionChecker from pyams_i18n.interfaces import II18n @@ -27,6 +28,7 @@ # import packages from persistent import Persistent from pyams_content.features.checker import BaseContentChecker +from pyams_content.features.renderer import RenderedContentMixin from pyams_utils.adapter import adapter_config, ContextAdapter from pyams_utils.registry import query_utility from pyams_utils.request import check_request @@ -72,8 +74,8 @@ # Base paragraph classes and subscribers # -@implementer(IBaseParagraph) -class BaseParagraph(Persistent, Contained): +@implementer(IBaseParagraph, IPreviewTarget) +class BaseParagraph(RenderedContentMixin, Persistent, Contained): """Base paragraph persistent class""" icon_class = '' diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/contact.py --- a/src/pyams_content/component/paragraph/contact.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/contact.py Fri May 25 11:28:17 2018 +0200 @@ -25,22 +25,22 @@ # import packages from pyams_content.component.paragraph import BaseParagraph, BaseParagraphFactory, BaseParagraphContentChecker -from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer +from pyams_content.features.renderer import RenderersVocabulary from pyams_file.property import FileProperty from pyams_utils.adapter import adapter_config +from pyams_utils.factory import factory_config from pyams_utils.registry import utility_config, get_utility -from pyams_utils.request import check_request from pyams_utils.traversing import get_parent from pyams_utils.vocabulary import vocabulary_config from zope.interface import implementer, alsoProvides from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pyams_content import _ @implementer(IContactParagraph) -class ContactParagraph(RenderedContentMixin, BaseParagraph): +@factory_config(provided=IContactParagraph) +class ContactParagraph(BaseParagraph): """Contact paragraph""" icon_class = 'fa-id-card-o' @@ -112,16 +112,7 @@ @vocabulary_config(name=CONTACT_PARAGRAPH_RENDERERS) -class ContactParagraphRendererVocabulary(SimpleVocabulary): +class ContactParagraphRendererVocabulary(RenderersVocabulary): """Contact paragraph renderers vocabulary""" - def __init__(self, context=None): - request = check_request() - translate = request.localizer.translate - registry = request.registry - if not IContactParagraph.providedBy(context): - context = ContactParagraph() - terms = [SimpleTerm(name, title=translate(adapter.label)) - for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), - key=lambda x: x[1].weight)] - super(ContactParagraphRendererVocabulary, self).__init__(terms) + content_interface = IContactParagraph diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/frame.py --- a/src/pyams_content/component/paragraph/frame.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/frame.py Fri May 25 11:28:17 2018 +0200 @@ -27,15 +27,14 @@ # import packages from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory -from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer +from pyams_content.features.renderer import RenderersVocabulary from pyams_utils.adapter import adapter_config +from pyams_utils.factory import factory_config from pyams_utils.registry import utility_config, get_utility -from pyams_utils.request import check_request from pyams_utils.traversing import get_parent from pyams_utils.vocabulary import vocabulary_config from zope.interface import implementer from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pyams_content import _ @@ -45,7 +44,8 @@ # @implementer(IFrameParagraph, IIllustrationTarget, IExtFileContainerTarget, ILinkContainerTarget) -class FrameParagraph(RenderedContentMixin, BaseParagraph): +@factory_config(provided=IFrameParagraph) +class FrameParagraph(BaseParagraph): """Framed text paragraph""" icon_class = 'fa-list-alt' @@ -91,16 +91,7 @@ @vocabulary_config(name=FRAME_PARAGRAPH_RENDERERS) -class FrameParagraphRendererVocabulary(SimpleVocabulary): +class FrameParagraphRendererVocabulary(RenderersVocabulary): """Framed text paragraph renderers vocabulary""" - def __init__(self, context=None): - request = check_request() - translate = request.localizer.translate - registry = request.registry - if not IFrameParagraph.providedBy(context): - context = FrameParagraph() - terms = [SimpleTerm(name, title=translate(adapter.label)) - for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), - key=lambda x: x[1].weight)] - super(FrameParagraphRendererVocabulary, self).__init__(terms) + content_interface = IFrameParagraph diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/header.py --- a/src/pyams_content/component/paragraph/header.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/header.py Fri May 25 11:28:17 2018 +0200 @@ -20,27 +20,26 @@ from pyams_content.component.paragraph.interfaces.header import IHeaderParagraph, HEADER_PARAGRAPH_TYPE, \ HEADER_PARAGRAPH_RENDERERS from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE -from pyams_content.features.renderer.interfaces import IContentRenderer from pyams_i18n.interfaces import II18n, II18nManager, INegotiator # import packages from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory -from pyams_content.features.renderer import RenderedContentMixin +from pyams_content.features.renderer import RenderersVocabulary from pyams_utils.adapter import adapter_config +from pyams_utils.factory import factory_config from pyams_utils.registry import utility_config, get_utility -from pyams_utils.request import check_request from pyams_utils.text import get_text_start from pyams_utils.traversing import get_parent from pyams_utils.vocabulary import vocabulary_config from zope.interface import implementer from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pyams_content import _ @implementer(IHeaderParagraph) -class HeaderParagraph(RenderedContentMixin, BaseParagraph): +@factory_config(provided=IHeaderParagraph) +class HeaderParagraph(BaseParagraph): """Header paragraph""" icon_class = 'fa-download fa-rotate-180' @@ -89,16 +88,7 @@ @vocabulary_config(name=HEADER_PARAGRAPH_RENDERERS) -class HeaderParagraphRendererVocabulary(SimpleVocabulary): +class HeaderParagraphRendererVocabulary(RenderersVocabulary): """Header paragraph renderers vocabulary""" - def __init__(self, context=None): - request = check_request() - translate = request.localizer.translate - registry = request.registry - if not IHeaderParagraph.providedBy(context): - context = HeaderParagraph() - terms = [SimpleTerm(name, title=translate(adapter.label)) - for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), - key=lambda x: x[1].weight)] - super(HeaderParagraphRendererVocabulary, self).__init__(terms) + content_interface = IHeaderParagraph diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/html.py --- a/src/pyams_content/component/paragraph/html.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/html.py Fri May 25 11:28:17 2018 +0200 @@ -9,7 +9,6 @@ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # -from pyams_sequence.interfaces import ISequentialIntIds __docformat__ = 'restructuredtext' @@ -24,19 +23,23 @@ from pyams_content.component.links.interfaces import ILinkContainerTarget, IInternalLink, IExternalLink, IMailtoLink from pyams_content.component.paragraph.interfaces import IParagraphFactory from pyams_content.component.paragraph.interfaces.html import RAW_PARAGRAPH_TYPE, IRawParagraph, HTML_PARAGRAPH_TYPE, \ - IHTMLParagraph + IHTMLParagraph, RAW_PARAGRAPH_RENDERERS, HTML_PARAGRAPH_RENDERERS from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE from pyams_i18n.interfaces import II18n, II18nManager, INegotiator +from pyams_sequence.interfaces import ISequentialIntIds from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent # import packages from pyams_content.component.links import InternalLink, ExternalLink, MailtoLink from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory +from pyams_content.features.renderer import RenderersVocabulary from pyams_utils.adapter import adapter_config +from pyams_utils.factory import factory_config from pyams_utils.registry import utility_config, get_utility from pyams_utils.request import check_request from pyams_utils.traversing import get_parent from pyams_utils.url import absolute_url +from pyams_utils.vocabulary import vocabulary_config from pyquery import PyQuery from pyramid.events import subscriber from pyramid.threadlocal import get_current_registry @@ -52,6 +55,7 @@ # @implementer(IRawParagraph) +@factory_config(provided=IRawParagraph) class RawParagraph(BaseParagraph): """Raw HTML paragraph""" @@ -59,6 +63,7 @@ icon_hint = _("Raw HTML ") body = FieldProperty(IRawParagraph['body']) + renderer = FieldProperty(IRawParagraph['renderer']) @utility_config(name=RAW_PARAGRAPH_TYPE, provides=IParagraphFactory) @@ -94,11 +99,19 @@ return output +@vocabulary_config(name=RAW_PARAGRAPH_RENDERERS) +class RawParagraphRendererVocabulary(RenderersVocabulary): + """Raw HTML paragraph renderers vocabulary""" + + content_interface = IRawParagraph + + # # HTML paragraph # @implementer(IHTMLParagraph, IIllustrationTarget, IExtFileContainerTarget, ILinkContainerTarget) +@factory_config(provided=IHTMLParagraph) class HTMLParagraph(BaseParagraph): """HTML paragraph""" @@ -106,6 +119,7 @@ icon_hint = _("Rich text") body = FieldProperty(IHTMLParagraph['body']) + renderer = FieldProperty(IHTMLParagraph['renderer']) @utility_config(name=HTML_PARAGRAPH_TYPE, provides=IParagraphFactory) @@ -223,3 +237,10 @@ else: output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang)) return output + + +@vocabulary_config(name=HTML_PARAGRAPH_RENDERERS) +class HTMLParagraphRendererVocabulary(RenderersVocabulary): + """HTML paragraph renderers vocabulary""" + + content_interface = IHTMLParagraph diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/interfaces/__init__.py --- a/src/pyams_content/component/paragraph/interfaces/__init__.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/interfaces/__init__.py Fri May 25 11:28:17 2018 +0200 @@ -16,6 +16,7 @@ # import standard library # import interfaces +from pyams_content.features.renderer import IRenderedContent from zope.annotation.interfaces import IAttributeAnnotatable from zope.container.interfaces import IOrderedContainer from zope.contentprovider.interfaces import IContentProvider @@ -32,7 +33,7 @@ PARAGRAPH_CONTAINER_KEY = 'pyams_content.paragraph' -class IBaseParagraph(IAttributeAnnotatable): +class IBaseParagraph(IRenderedContent, IAttributeAnnotatable): """Base paragraph interface""" containers('.IParagraphContainer') diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/interfaces/contact.py --- a/src/pyams_content/component/paragraph/interfaces/contact.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/interfaces/contact.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,6 @@ # import interfaces from pyams_content.component.paragraph import IBaseParagraph -from pyams_content.features.renderer import IRenderedContent from pyams_content.shared.form.interfaces import FORM_CONTENT_TYPE # import packages @@ -44,7 +43,7 @@ CONTACT_PARAGRAPH_RENDERERS = 'PyAMS.paragraph.contact.renderers' -class IContactParagraph(IRenderedContent, IBaseParagraph): +class IContactParagraph(IBaseParagraph): """Contact paragraph interface""" name = TextLine(title=_("Contact identity"), diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/interfaces/frame.py --- a/src/pyams_content/component/paragraph/interfaces/frame.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/interfaces/frame.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,6 @@ # import interfaces from pyams_content.component.paragraph.interfaces import IBaseParagraph -from pyams_content.features.renderer import IRenderedContent # import packages from pyams_i18n.schema import I18nHTMLField @@ -34,7 +33,7 @@ FRAME_PARAGRAPH_RENDERERS = 'PyAMS.paragraph.text.renderers' -class IFrameParagraph(IRenderedContent, IBaseParagraph): +class IFrameParagraph(IBaseParagraph): """Framed text paragraph interface""" body = I18nHTMLField(title=_("Frame body"), diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/interfaces/header.py --- a/src/pyams_content/component/paragraph/interfaces/header.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/interfaces/header.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,6 @@ # import interfaces from pyams_content.component.paragraph.interfaces import IBaseParagraph -from pyams_content.features.renderer import IRenderedContent # import packages from pyams_i18n.schema import I18nTextField @@ -34,7 +33,7 @@ HEADER_PARAGRAPH_RENDERERS = 'PyAMS.paragraph.header.renderers' -class IHeaderParagraph(IRenderedContent, IBaseParagraph): +class IHeaderParagraph(IBaseParagraph): """Header paragraph""" header = I18nTextField(title=_("Header"), diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/interfaces/html.py --- a/src/pyams_content/component/paragraph/interfaces/html.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/interfaces/html.py Fri May 25 11:28:17 2018 +0200 @@ -20,6 +20,7 @@ # import packages from pyams_i18n.schema import I18nHTMLField, I18nTextField +from zope.schema import Choice from pyams_content import _ @@ -29,6 +30,7 @@ # RAW_PARAGRAPH_TYPE = 'raw' +RAW_PARAGRAPH_RENDERERS = 'PyAMS.paragraph.raw.renderers' class IRawParagraph(IBaseParagraph): @@ -39,12 +41,18 @@ "care!!"), required=False) + renderer = Choice(title=_("Raw HTML code template"), + description=_("Presentation template used for this paragraph"), + vocabulary=RAW_PARAGRAPH_RENDERERS, + default='default') + # # HTML paragraph # HTML_PARAGRAPH_TYPE = 'HTML' +HTML_PARAGRAPH_RENDERERS = 'PyAMS.paragraph.html.renderers' class IHTMLParagraph(IBaseParagraph): @@ -52,3 +60,8 @@ body = I18nHTMLField(title=_("Body"), required=False) + + renderer = Choice(title=_("Body template"), + description=_("Presentation template used for this paragraph"), + vocabulary=HTML_PARAGRAPH_RENDERERS, + default='default') diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/interfaces/keynumber.py --- a/src/pyams_content/component/paragraph/interfaces/keynumber.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/interfaces/keynumber.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,6 @@ # import interfaces from pyams_content.component.paragraph import IBaseParagraph -from pyams_content.features.renderer import IRenderedContent from pyams_content.interfaces.container import IOrderedContainer from zope.annotation.interfaces import IAttributeAnnotatable @@ -77,7 +76,7 @@ KEYNUMBER_PARAGRAPH_RENDERERS = 'PyAMS.keynumbers.renderers' -class IKeyNumberParagraph(IKeyNumberContainerTarget, IRenderedContent, IBaseParagraph): +class IKeyNumberParagraph(IKeyNumberContainerTarget, IBaseParagraph): """Key numbers paragraph interface""" renderer = Choice(title=_("Key numbers template"), diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/interfaces/keypoint.py --- a/src/pyams_content/component/paragraph/interfaces/keypoint.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/interfaces/keypoint.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,6 @@ # import interfaces from pyams_content.component.paragraph.interfaces import IBaseParagraph -from pyams_content.features.renderer import IRenderedContent # import packages from pyams_i18n.schema import I18nTextField @@ -34,7 +33,7 @@ KEYPOINTS_PARAGRAPH_RENDERERS = 'PyAMS.paragraph.keypoint.renderers' -class IKeypointsParagraph(IRenderedContent, IBaseParagraph): +class IKeypointsParagraph(IBaseParagraph): """Key points paragraph""" body = I18nTextField(title=_("Key points"), diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/interfaces/milestone.py --- a/src/pyams_content/component/paragraph/interfaces/milestone.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/interfaces/milestone.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,6 @@ # import interfaces from pyams_content.component.paragraph import IBaseParagraph -from pyams_content.features.renderer import IRenderedContent from pyams_content.interfaces.container import IOrderedContainer from zope.annotation.interfaces import IAttributeAnnotatable @@ -77,7 +76,7 @@ MILESTONE_PARAGRAPH_RENDERERS = 'PyAMS.milestones.renderers' -class IMilestoneParagraph(IMilestoneContainerTarget, IRenderedContent, IBaseParagraph): +class IMilestoneParagraph(IMilestoneContainerTarget, IBaseParagraph): """Milestones paragraph interface""" renderer = Choice(title=_("Milestones template"), diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/interfaces/pictogram.py --- a/src/pyams_content/component/paragraph/interfaces/pictogram.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/interfaces/pictogram.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,6 @@ # import interfaces from pyams_content.component.paragraph.interfaces import IBaseParagraph -from pyams_content.features.renderer.interfaces import IRenderedContent from pyams_content.interfaces.container import IOrderedContainer from pyams_content.reference.pictograms.interfaces import SELECTED_PICTOGRAM_VOCABULARY from zope.annotation import IAttributeAnnotatable @@ -81,7 +80,7 @@ PICTOGRAM_PARAGRAPH_RENDERERS = 'MyAMS.pictograms.renderers' -class IPictogramParagraph(IPictogramContainerTarget, IRenderedContent, IBaseParagraph): +class IPictogramParagraph(IPictogramContainerTarget, IBaseParagraph): """Pictograms paragraph interface""" renderer = Choice(title=_("Pictograms template"), diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/interfaces/verbatim.py --- a/src/pyams_content/component/paragraph/interfaces/verbatim.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/interfaces/verbatim.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,6 @@ # import interfaces from pyams_content.component.paragraph.interfaces import IBaseParagraph -from pyams_content.features.renderer import IRenderedContent # import packages from pyams_i18n.schema import I18nTextLineField, I18nTextField @@ -34,7 +33,7 @@ VERBATIM_PARAGRAPH_RENDERERS = 'PyAMS.paragraph.verbatim.renderers' -class IVerbatimParagraph(IRenderedContent, IBaseParagraph): +class IVerbatimParagraph(IBaseParagraph): """Verbatim paragraph interface""" quote = I18nTextField(title=_("Quoted text"), diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/interfaces/video.py --- a/src/pyams_content/component/paragraph/interfaces/video.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/interfaces/video.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,6 @@ # import interfaces from pyams_content.component.paragraph.interfaces import IBaseParagraph -from pyams_content.features.renderer.interfaces import IRenderedContent # import packages from pyams_file.schema import VideoField @@ -35,7 +34,7 @@ VIDEO_PARAGRAPH_RENDERERS = 'PyAMS.paragraph.video.renderers' -class IVideoParagraph(IRenderedContent, IBaseParagraph): +class IVideoParagraph(IBaseParagraph): """Video paragraph""" body = I18nHTMLField(title=_("Body"), diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/keynumber.py --- a/src/pyams_content/component/paragraph/keynumber.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/keynumber.py Fri May 25 11:28:17 2018 +0200 @@ -33,8 +33,9 @@ from pyams_catalog.utils import index_object from pyams_content.component.paragraph import BaseParagraph, BaseParagraphFactory, BaseParagraphContentChecker from pyams_content.features.checker import BaseContentChecker -from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer +from pyams_content.features.renderer import RenderersVocabulary from pyams_utils.adapter import adapter_config, ContextAdapter +from pyams_utils.factory import factory_config from pyams_utils.registry import get_current_registry, get_utility, utility_config from pyams_utils.request import check_request from pyams_utils.traversing import get_parent @@ -46,7 +47,6 @@ from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent from zope.location import locate from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pyams_content import _ @@ -206,7 +206,8 @@ @implementer(IKeyNumberParagraph) -class KeyNumberParagraph(RenderedContentMixin, BaseParagraph): +@factory_config(provided=IKeyNumberParagraph) +class KeyNumberParagraph(BaseParagraph): """Key numbers paragraph""" icon_class = 'fa-list-ol' @@ -256,16 +257,7 @@ @vocabulary_config(name=KEYNUMBER_PARAGRAPH_RENDERERS) -class KeyNumberParagraphRendererVocabulary(SimpleVocabulary): +class KeyNumberParagraphRendererVocabulary(RenderersVocabulary): """Key numbers paragraph renderers vocabulary""" - def __init__(self, context=None): - request = check_request() - translate = request.localizer.translate - registry = request.registry - if not IKeyNumberParagraph.providedBy(context): - context = KeyNumberParagraph() - terms = [SimpleTerm(name, title=translate(adapter.label)) - for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), - key=lambda x: x[1].weight)] - super(KeyNumberParagraphRendererVocabulary, self).__init__(terms) + content_interface = IKeyNumberParagraph diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/keypoint.py --- a/src/pyams_content/component/paragraph/keypoint.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/keypoint.py Fri May 25 11:28:17 2018 +0200 @@ -20,27 +20,26 @@ from pyams_content.component.paragraph.interfaces.keypoint import IKeypointsParagraph, KEYPOINTS_PARAGRAPH_TYPE, \ KEYPOINTS_PARAGRAPH_RENDERERS from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE -from pyams_content.features.renderer.interfaces import IContentRenderer from pyams_i18n.interfaces import II18n, II18nManager, INegotiator # import packages from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory -from pyams_content.features.renderer import RenderedContentMixin +from pyams_content.features.renderer import RenderersVocabulary from pyams_utils.adapter import adapter_config +from pyams_utils.factory import factory_config from pyams_utils.registry import utility_config, get_utility -from pyams_utils.request import check_request from pyams_utils.text import get_text_start from pyams_utils.traversing import get_parent from pyams_utils.vocabulary import vocabulary_config from zope.interface import implementer from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pyams_content import _ @implementer(IKeypointsParagraph) -class KeypointsParagraph(RenderedContentMixin, BaseParagraph): +@factory_config(provided=IKeypointsParagraph) +class KeypointsParagraph(BaseParagraph): """Key points paragraph""" icon_class = 'fa-key' @@ -90,16 +89,7 @@ @vocabulary_config(name=KEYPOINTS_PARAGRAPH_RENDERERS) -class KeypointsParagraphRendererVocabulary(SimpleVocabulary): +class KeypointsParagraphRendererVocabulary(RenderersVocabulary): """Key points paragraph renderers vocabulary""" - def __init__(self, context=None): - request = check_request() - translate = request.localizer.translate - registry = request.registry - if not IKeypointsParagraph.providedBy(context): - context = KeypointsParagraph() - terms = [SimpleTerm(name, title=translate(adapter.label)) - for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), - key=lambda x: x[1].weight)] - super(KeypointsParagraphRendererVocabulary, self).__init__(terms) + content_interface = IKeypointsParagraph diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/milestone.py --- a/src/pyams_content/component/paragraph/milestone.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/milestone.py Fri May 25 11:28:17 2018 +0200 @@ -34,8 +34,9 @@ from pyams_catalog.utils import index_object from pyams_content.component.paragraph import BaseParagraph, BaseParagraphFactory, BaseParagraphContentChecker from pyams_content.features.checker import BaseContentChecker -from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer +from pyams_content.features.renderer import RenderersVocabulary from pyams_utils.adapter import adapter_config, ContextAdapter +from pyams_utils.factory import factory_config from pyams_utils.registry import get_current_registry, get_utility, utility_config from pyams_utils.request import check_request from pyams_utils.traversing import get_parent @@ -47,7 +48,6 @@ from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent from zope.location import locate from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pyams_content import _ @@ -221,7 +221,8 @@ @implementer(IMilestoneParagraph) -class MilestoneParagraph(RenderedContentMixin, BaseParagraph): +@factory_config(provided=IMilestoneParagraph) +class MilestoneParagraph(BaseParagraph): """Milestones paragraph""" icon_class = 'fa-arrows-h' @@ -271,16 +272,7 @@ @vocabulary_config(name=MILESTONE_PARAGRAPH_RENDERERS) -class MilestoneParagraphRendererVocabulary(SimpleVocabulary): +class MilestoneParagraphRendererVocabulary(RenderersVocabulary): """Milestones paragraph renderers vocabulary""" - def __init__(self, context=None): - request = check_request() - translate = request.localizer.translate - registry = request.registry - if not IMilestoneParagraph.providedBy(context): - context = MilestoneParagraph() - terms = [SimpleTerm(name, title=translate(adapter.label)) - for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), - key=lambda x: x[1].weight)] - super(MilestoneParagraphRendererVocabulary, self).__init__(terms) + content_interface = IMilestoneParagraph diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/pictogram.py --- a/src/pyams_content/component/paragraph/pictogram.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/pictogram.py Fri May 25 11:28:17 2018 +0200 @@ -23,7 +23,6 @@ IPictogramContainer, PICTOGRAM_CONTAINER_KEY, IPictogramParagraph, PICTOGRAM_PARAGRAPH_TYPE, \ PICTOGRAM_PARAGRAPH_RENDERERS from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE, ERROR_VALUE -from pyams_content.features.renderer.interfaces import IContentRenderer from pyams_content.reference.pictograms.interfaces import IPictogramTable from pyams_form.interfaces.form import IFormContextPermissionChecker from pyams_i18n.interfaces import II18n, II18nManager, INegotiator @@ -36,8 +35,9 @@ from pyams_catalog.utils import index_object from pyams_content.component.paragraph import BaseParagraph, BaseParagraphFactory, BaseParagraphContentChecker from pyams_content.features.checker import BaseContentChecker -from pyams_content.features.renderer import RenderedContentMixin +from pyams_content.features.renderer import RenderersVocabulary from pyams_utils.adapter import adapter_config, ContextAdapter +from pyams_utils.factory import factory_config from pyams_utils.registry import query_utility, get_current_registry, get_utility, utility_config from pyams_utils.request import check_request from pyams_utils.traversing import get_parent @@ -49,7 +49,6 @@ from zope.interface import implementer from zope.location import locate from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pyams_content import _ @@ -212,7 +211,8 @@ @implementer(IPictogramParagraph, IIllustrationTarget) -class PictogramParagraph(RenderedContentMixin, BaseParagraph): +@factory_config(provided=IPictogramParagraph) +class PictogramParagraph(BaseParagraph): """Pictograms paragraph""" icon_class = 'fa-linode' @@ -262,16 +262,7 @@ @vocabulary_config(name=PICTOGRAM_PARAGRAPH_RENDERERS) -class PictogramParagraphRendererVocabulary(SimpleVocabulary): +class PictogramParagraphRendererVocabulary(RenderersVocabulary): """Pictograms paragraph renderers vocabulary""" - def __init__(self, context=None): - request = check_request() - translate = request.localizer.translate - registry = request.registry - if not IPictogramParagraph.providedBy(context): - context = PictogramParagraph() - terms = [SimpleTerm(name, title=translate(adapter.label)) - for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), - key=lambda x: x[1].weight)] - super(PictogramParagraphRendererVocabulary, self).__init__(terms) + content_interface = IPictogramParagraph diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/verbatim.py --- a/src/pyams_content/component/paragraph/verbatim.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/verbatim.py Fri May 25 11:28:17 2018 +0200 @@ -25,15 +25,14 @@ # import packages from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory -from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer +from pyams_content.features.renderer import RenderersVocabulary from pyams_utils.adapter import adapter_config +from pyams_utils.factory import factory_config from pyams_utils.registry import utility_config, get_utility -from pyams_utils.request import check_request from pyams_utils.traversing import get_parent from pyams_utils.vocabulary import vocabulary_config from zope.interface import implementer from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pyams_content import _ @@ -43,7 +42,8 @@ # @implementer(IVerbatimParagraph, IIllustrationTarget) -class VerbatimParagraph(RenderedContentMixin, BaseParagraph): +@factory_config(provided=IVerbatimParagraph) +class VerbatimParagraph(BaseParagraph): """Verbatim paragraph""" icon_class = 'fa-quote-right' @@ -96,16 +96,7 @@ @vocabulary_config(name=VERBATIM_PARAGRAPH_RENDERERS) -class VerbatimParagraphRendererVocabulary(SimpleVocabulary): +class VerbatimParagraphRendererVocabulary(RenderersVocabulary): """Verbatim paragraph renderers vocabulary""" - def __init__(self, context=None): - request = check_request() - translate = request.localizer.translate - registry = request.registry - if not IVerbatimParagraph.providedBy(context): - context = VerbatimParagraph() - terms = [SimpleTerm(name, title=translate(adapter.label)) - for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), - key=lambda x: x[1].weight)] - super(VerbatimParagraphRendererVocabulary, self).__init__(terms) + content_interface = IVerbatimParagraph diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/video.py --- a/src/pyams_content/component/paragraph/video.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/video.py Fri May 25 11:28:17 2018 +0200 @@ -28,23 +28,23 @@ # import packages from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory from pyams_content.component.paragraph.html import check_associations -from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer +from pyams_content.features.renderer import RenderersVocabulary from pyams_file.property import FileProperty from pyams_utils.adapter import adapter_config +from pyams_utils.factory import factory_config from pyams_utils.registry import utility_config, get_utility -from pyams_utils.request import check_request from pyams_utils.traversing import get_parent from pyams_utils.vocabulary import vocabulary_config from pyramid.events import subscriber from zope.interface import implementer from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pyams_content import _ @implementer(IVideoParagraph, IExtFileContainerTarget, ILinkContainerTarget) -class VideoParagraph(RenderedContentMixin, BaseParagraph): +@factory_config(provided=IVideoParagraph) +class VideoParagraph(BaseParagraph): """Video paragraph class""" icon_class = 'fa-film' @@ -111,16 +111,7 @@ @vocabulary_config(name=VIDEO_PARAGRAPH_RENDERERS) -class VideoParagraphRendererVocabulary(SimpleVocabulary): +class VideoParagraphRendererVocabulary(RenderersVocabulary): """Video paragraph renderers vocabulary""" - def __init__(self, context=None): - request = check_request() - translate = request.localizer.translate - registry = request.registry - if not IVideoParagraph.providedBy(context): - context = VideoParagraph() - terms = [SimpleTerm(name, title=translate(adapter.label)) - for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), - key=lambda x: x[1].weight)] - super(VideoParagraphRendererVocabulary, self).__init__(terms) + content_interface = IVideoParagraph diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/zmi/__init__.py --- a/src/pyams_content/component/paragraph/zmi/__init__.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/zmi/__init__.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,7 @@ # import interfaces from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IBaseParagraph, IParagraphFactory, \ - IParagraphFactorySettings + IParagraphFactorySettings, IParagraphRenderer from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerView from pyams_content.interfaces import MANAGE_TOOL_PERMISSION from pyams_content.shared.common.interfaces import IWfSharedContent @@ -31,6 +31,7 @@ # import packages from pyams_content.component.paragraph.zmi.container import ParagraphContainerTable, ParagraphContainerBaseTable +from pyams_content.features.renderer.zmi import BaseRenderedContentRenderer from pyams_form.form import AJAXEditForm, AJAXAddForm from pyams_form.help import FormHelp from pyams_form.schema import ActionButton, CloseButton @@ -205,8 +206,8 @@ """Paragraph edit form buttons""" preview = ActionButton(name='preview', title=_("Preview"), - label_css_class='fa fa-fw fa-eye', - url='preview.html', + label_css_class='fa fa-fw fa-binoculars', + url='content-preview.html', modal_target=True) close = CloseButton(name='close', title=_("Cancel")) @@ -242,3 +243,12 @@ output.setdefault('events', []).append( get_json_paragraph_refresh_event(self.context, self.request)) return output + + +# +# Base paragraph renderer +# + +@adapter_config(context=(IBaseParagraph, IPyAMSLayer), provides=IParagraphRenderer) +class BaseParagraphRenderer(BaseRenderedContentRenderer): + """Base paragraph renderer""" diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/zmi/contact.py --- a/src/pyams_content/component/paragraph/zmi/contact.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/zmi/contact.py Fri May 25 11:28:17 2018 +0200 @@ -17,7 +17,7 @@ # import interfaces from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ - IBaseParagraph, IParagraphRenderer + IBaseParagraph from pyams_content.component.paragraph.interfaces.contact import CONTACT_PARAGRAPH_TYPE, IContactParagraph from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerView, IParagraphInnerEditor from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION @@ -32,7 +32,6 @@ from pyams_content.component.paragraph.zmi import BaseParagraphAddMenu, BaseParagraphAJAXAddForm, \ BaseParagraphPropertiesEditForm, BaseParagraphAJAXEditForm, get_json_paragraph_refresh_event, \ IParagraphEditFormButtons -from pyams_content.features.renderer.zmi import BaseRenderedContentRenderer from pyams_content.features.renderer.zmi.widget import RendererFieldWidget from pyams_pagelet.pagelet import pagelet_config from pyams_skin.event import get_json_form_refresh_event @@ -150,12 +149,3 @@ output.setdefault('events', []).append(get_json_form_refresh_event(self.context, self.request, ContactParagraphInnerEditForm)) return output - - -# -# Contact paragraph renderer -# - -@adapter_config(context=(IContactParagraph, IPyAMSLayer), provides=IParagraphRenderer) -class ContactParagraphRenderer(BaseRenderedContentRenderer): - """Contact paragraph renderer""" diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/zmi/frame.py --- a/src/pyams_content/component/paragraph/zmi/frame.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/zmi/frame.py Fri May 25 11:28:17 2018 +0200 @@ -18,8 +18,7 @@ # import interfaces from pyams_content.component.association.interfaces import IAssociationTarget from pyams_content.component.association.zmi.interfaces import IAssociationsParentForm -from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ - IParagraphRenderer +from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer from pyams_content.component.paragraph.interfaces.frame import IFrameParagraph, FRAME_PARAGRAPH_TYPE from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphContainerView from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION @@ -38,7 +37,6 @@ IParagraphEditFormButtons from pyams_content.component.paragraph.zmi.container import ParagraphContainerTable, \ ParagraphTitleToolbarViewletManager -from pyams_content.features.renderer.zmi import BaseRenderedContentRenderer from pyams_content.features.renderer.zmi.widget import RendererFieldWidget from pyams_pagelet.pagelet import pagelet_config from pyams_skin.event import get_json_switched_table_refresh_event, get_json_widget_refresh_event @@ -200,12 +198,3 @@ output.setdefault('events', []).append( get_json_widget_refresh_event(self.context, self.request, FrameParagraphInnerEditForm, 'renderer')) return output - - -# -# Framed text paragraph renderer -# - -@adapter_config(context=(IFrameParagraph, IPyAMSLayer), provides=IParagraphRenderer) -class FrameParagraphRenderer(BaseRenderedContentRenderer): - """Framed text paragraph renderer""" diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/zmi/header.py --- a/src/pyams_content/component/paragraph/zmi/header.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/zmi/header.py Fri May 25 11:28:17 2018 +0200 @@ -16,8 +16,7 @@ # import standard library # import interfaces -from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ - IParagraphRenderer +from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer from pyams_content.component.paragraph.interfaces.header import IHeaderParagraph, HEADER_PARAGRAPH_TYPE from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphContainerView from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION @@ -30,7 +29,6 @@ from pyams_content.component.paragraph.header import HeaderParagraph from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \ BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, get_json_paragraph_refresh_event, IParagraphEditFormButtons -from pyams_content.features.renderer.zmi import BaseRenderedContentRenderer from pyams_content.features.renderer.zmi.widget import RendererFieldWidget from pyams_pagelet.pagelet import pagelet_config from pyams_skin.event import get_json_widget_refresh_event @@ -152,12 +150,3 @@ output.setdefault('events', []).append(get_json_widget_refresh_event(self.context, self.request, HeaderParagraphInnerEditForm, 'renderer')) return output - - -# -# Header paragraph renderer -# - -@adapter_config(context=(IHeaderParagraph, IPyAMSLayer), provides=IParagraphRenderer) -class HeaderParagraphRenderer(BaseRenderedContentRenderer): - """Header paragraph renderer""" diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/zmi/html.py --- a/src/pyams_content/component/paragraph/zmi/html.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/zmi/html.py Fri May 25 11:28:17 2018 +0200 @@ -18,15 +18,13 @@ # import interfaces from pyams_content.component.association.interfaces import IAssociationTarget from pyams_content.component.association.zmi.interfaces import IAssociationsParentForm -from pyams_content.component.illustration.interfaces import IIllustration from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphFactorySettings, \ - IParagraphContainer, IParagraphRenderer + IParagraphContainer from pyams_content.component.paragraph.interfaces.html import IHTMLParagraph, IRawParagraph, RAW_PARAGRAPH_TYPE, \ HTML_PARAGRAPH_TYPE from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphContainerView from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION from pyams_form.interfaces.form import IInnerForm -from pyams_i18n.interfaces import II18n from pyams_skin.interfaces.viewlet import IToolbarAddingMenu from pyams_skin.layer import IPyAMSLayer from pyams_zmi.interfaces import IPropertiesEditForm @@ -38,14 +36,14 @@ from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \ BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, get_json_paragraph_toolbar_refresh_event, \ IParagraphEditFormButtons +from pyams_content.features.renderer.zmi.widget import RendererFieldWidget from pyams_form.security import ProtectedFormObjectMixin from pyams_pagelet.pagelet import pagelet_config from pyams_skin.event import get_json_switched_table_refresh_event from pyams_skin.viewlet.menu import MenuDivider -from pyams_template.template import template_config from pyams_utils.adapter import adapter_config from pyams_utils.traversing import get_parent -from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider +from pyams_viewlet.viewlet import viewlet_config from pyams_zmi.form import AdminDialogAddForm from pyramid.view import view_config from z3c.form import field, button @@ -125,6 +123,8 @@ icon_css_class = 'fa fa-fw fa-code' fields = field.Fields(IRawParagraph).omit('__parent__', '__name__', 'visible') + fields['renderer'].widgetFactory = RendererFieldWidget + ajax_handler = 'properties.json' edit_permission = MANAGE_CONTENT_PERMISSION @@ -163,27 +163,6 @@ # -# Raw HTML paragraph renderer -# - -@adapter_config(context=(IRawParagraph, IPyAMSLayer), provides=IParagraphRenderer) -@template_config(template='templates/raw-render.pt', layer=IPyAMSLayer) -class RawParagraphRenderer(BaseContentProvider): - """Raw HTML paragraph renderer""" - - language = None - - def update(self): - i18n = II18n(self.context) - if self.language: - for attr in ('title', 'body'): - setattr(self, attr, i18n.get_attribute(attr, self.language, request=self.request)) - else: - for attr in ('title', 'body'): - setattr(self, attr, i18n.query_attribute(attr, request=self.request)) - - -# # Rich text paragraph # @@ -245,6 +224,8 @@ input_css_class = 'col-md-10' fields = field.Fields(IHTMLParagraph).omit('__parent__', '__name__', 'visible') + fields['renderer'].widgetFactory = RendererFieldWidget + ajax_handler = 'properties.json' edit_permission = MANAGE_CONTENT_PERMISSION @@ -308,36 +289,3 @@ output.setdefault('events', []).append( get_json_switched_table_refresh_event(self.context, self.request, AssociationsTable)) return output - - -# -# Rich text paragraph renderer -# - -@adapter_config(context=(IHTMLParagraph, IPyAMSLayer), provides=IParagraphRenderer) -@template_config(template='templates/html-render.pt', layer=IPyAMSLayer) -class HTMLParagraphRenderer(BaseContentProvider): - """Rich text paragraph renderer""" - - illustration = None - illustration_renderer = None - language = None - - def update(self): - i18n = II18n(self.context) - if self.language: - for attr in ('title', 'body'): - setattr(self, attr, i18n.get_attribute(attr, self.language, request=self.request)) - else: - for attr in ('title', 'body'): - setattr(self, attr, i18n.query_attribute(attr, request=self.request)) - self.illustration = IIllustration(self.context) - if self.illustration.data: - renderer = self.illustration_renderer = self.illustration.get_renderer() - if renderer is not None: - renderer.update() - - def render_illustration(self): - if not self.illustration_renderer: - return '' - return self.illustration_renderer.render() diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/zmi/keynumber.py --- a/src/pyams_content/component/paragraph/zmi/keynumber.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/zmi/keynumber.py Fri May 25 11:28:17 2018 +0200 @@ -17,8 +17,7 @@ import json # import interfaces -from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ - IParagraphRenderer +from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer from pyams_content.component.paragraph.interfaces.keynumber import KEYNUMBER_PARAGRAPH_TYPE, IKeyNumberParagraph, \ IKeyNumberContainer, IKeyNumberContainerTarget, IKeyNumber from pyams_content.component.paragraph.zmi import IParagraphContainerView, IParagraphEditFormButtons @@ -36,7 +35,6 @@ from pyams_content.component.paragraph.keynumber import KeyNumberParagraph, KeyNumber from pyams_content.component.paragraph.zmi import BaseParagraphAddMenu, BaseParagraphAJAXAddForm, \ BaseParagraphPropertiesEditForm, BaseParagraphAJAXEditForm -from pyams_content.features.renderer.zmi import BaseRenderedContentRenderer from pyams_content.features.renderer.zmi.widget import RendererFieldWidget from pyams_form.form import AJAXAddForm, AJAXEditForm from pyams_form.security import ProtectedFormObjectMixin @@ -165,15 +163,6 @@ # -# Key number paragraph renderer -# - -@adapter_config(context=(IKeyNumberParagraph, IPyAMSLayer), provides=IParagraphRenderer) -class KeyNumberParagraphRenderer(BaseRenderedContentRenderer): - """Key number paragraph renderer""" - - -# # Key number items table view # diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/zmi/keypoint.py --- a/src/pyams_content/component/paragraph/zmi/keypoint.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/zmi/keypoint.py Fri May 25 11:28:17 2018 +0200 @@ -16,8 +16,7 @@ # import standard library # import interfaces -from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ - IParagraphRenderer +from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer from pyams_content.component.paragraph.interfaces.keypoint import IKeypointsParagraph, KEYPOINTS_PARAGRAPH_TYPE from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphContainerView from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION @@ -30,7 +29,6 @@ from pyams_content.component.paragraph.keypoint import KeypointsParagraph from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \ BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, get_json_paragraph_refresh_event, IParagraphEditFormButtons -from pyams_content.features.renderer.zmi import BaseRenderedContentRenderer from pyams_content.features.renderer.zmi.widget import RendererFieldWidget from pyams_pagelet.pagelet import pagelet_config from pyams_skin.event import get_json_widget_refresh_event @@ -153,12 +151,3 @@ output.setdefault('events', []).append( get_json_widget_refresh_event(self.context, self.request, KeypointsParagraphInnerEditForm, 'renderer')) return output - - -# -# Key points paragraph renderer -# - -@adapter_config(context=(IKeypointsParagraph, IPyAMSLayer), provides=IParagraphRenderer) -class KeypointsParagraphRenderer(BaseRenderedContentRenderer): - """Key points paragraph renderer""" diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/zmi/milestone.py --- a/src/pyams_content/component/paragraph/zmi/milestone.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/zmi/milestone.py Fri May 25 11:28:17 2018 +0200 @@ -17,8 +17,7 @@ import json # import interfaces -from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ - IParagraphRenderer +from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer from pyams_content.component.paragraph.interfaces.milestone import MILESTONE_PARAGRAPH_TYPE, IMilestoneParagraph, \ IMilestoneContainer, IMilestoneContainerTarget, IMilestone from pyams_content.component.paragraph.zmi import IParagraphContainerView, IParagraphEditFormButtons @@ -36,7 +35,6 @@ from pyams_content.component.paragraph.milestone import MilestoneParagraph, Milestone from pyams_content.component.paragraph.zmi import BaseParagraphAddMenu, BaseParagraphAJAXAddForm, \ BaseParagraphPropertiesEditForm, BaseParagraphAJAXEditForm -from pyams_content.features.renderer.zmi import BaseRenderedContentRenderer from pyams_content.features.renderer.zmi.widget import RendererFieldWidget from pyams_form.form import AJAXAddForm, AJAXEditForm from pyams_form.security import ProtectedFormObjectMixin @@ -169,15 +167,6 @@ # -# Milestone paragraph renderer -# - -@adapter_config(context=(IMilestoneParagraph, IPyAMSLayer), provides=IParagraphRenderer) -class MilestoneParagraphRenderer(BaseRenderedContentRenderer): - """Milestone paragraph renderer""" - - -# # Milestone items table view # diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/zmi/pictogram.py --- a/src/pyams_content/component/paragraph/zmi/pictogram.py Wed May 23 15:30:41 2018 +0200 +++ b/src/pyams_content/component/paragraph/zmi/pictogram.py Fri May 25 11:28:17 2018 +0200 @@ -17,8 +17,7 @@ import json # import interfaces -from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ - IParagraphRenderer +from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer from pyams_content.component.paragraph.interfaces.pictogram import PICTOGRAM_PARAGRAPH_TYPE, IPictogramParagraph, \ IPictogramContainer, IPictogramContainerTarget, IPictogramItem from pyams_content.component.paragraph.zmi import IParagraphContainerView, IParagraphEditFormButtons @@ -38,7 +37,6 @@ from pyams_content.component.paragraph.pictogram import PictogramParagraph, PictogramItem from pyams_content.component.paragraph.zmi import BaseParagraphAddMenu, BaseParagraphAJAXAddForm, \ BaseParagraphPropertiesEditForm, BaseParagraphAJAXEditForm -from pyams_content.features.renderer.zmi import BaseRenderedContentRenderer from pyams_content.features.renderer.zmi.widget import RendererFieldWidget from pyams_form.form import AJAXAddForm, AJAXEditForm from pyams_form.security import ProtectedFormObjectMixin @@ -168,15 +166,6 @@ # -# Pictogram paragraph renderer -# - -@adapter_config(context=(IPictogramParagraph, IPyAMSLayer), provides=IParagraphRenderer) -class PictogramParagraphRenderer(BaseRenderedContentRenderer): - """Pictogram paragraph renderer""" - - -# # Pictogram items table view # diff -r 26a58877d1aa -r b438528e5bb3 src/pyams_content/component/paragraph/zmi/templates/html-render.pt --- a/src/pyams_content/component/paragraph/zmi/templates/html-render.pt Wed May 23 15:30:41 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -