--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/paragraph/interfaces/verbatim.py Wed Mar 07 14:46:15 2018 +0100
@@ -0,0 +1,55 @@
+#
+# 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 IBaseParagraph
+from pyams_content.features.renderer import IRenderedContent
+
+# import packages
+from pyams_i18n.schema import I18nTextLineField, I18nTextField
+from zope.schema import Choice, TextLine
+
+from pyams_content import _
+
+
+#
+# Verbatim paragraph
+#
+
+VERBATIM_PARAGRAPH_TYPE = 'Verbatim'
+VERBATIM_PARAGRAPH_RENDERERS = 'PyAMS.paragraph.verbatim.renderers'
+
+
+class IVerbatimParagraph(IRenderedContent, IBaseParagraph):
+ """Verbatim paragraph interface"""
+
+ quote = I18nTextField(title=_("Quoted text"),
+ description=_("Quotation marks will be added automatically by presentation template"),
+ required=True)
+
+ author = TextLine(title=_("Author"),
+ description=_("Name of the quote author"),
+ required=False)
+
+ charge = I18nTextLineField(title=_("In charge of"),
+ description=_("Label of author function"),
+ required=False)
+
+ renderer = Choice(title=_("Verbatim template"),
+ description=_("Presentation template used for this paragraph"),
+ vocabulary=VERBATIM_PARAGRAPH_RENDERERS,
+ default='default')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/paragraph/verbatim.py Wed Mar 07 14:46:15 2018 +0100
@@ -0,0 +1,111 @@
+#
+# 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.illustration.interfaces import IIllustrationTarget
+from pyams_content.component.paragraph.interfaces import IParagraphFactory
+from pyams_content.component.paragraph.interfaces.verbatim import IVerbatimParagraph, VERBATIM_PARAGRAPH_TYPE, \
+ VERBATIM_PARAGRAPH_RENDERERS
+from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
+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, IContentRenderer
+from pyams_utils.adapter import adapter_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 _
+
+
+#
+# Frame paragraph
+#
+
+@implementer(IVerbatimParagraph, IIllustrationTarget)
+class VerbatimParagraph(RenderedContentMixin, BaseParagraph):
+ """Verbatim paragraph"""
+
+ icon_class = 'fa-quote-right'
+ icon_hint = _("Verbatim")
+
+ quote = FieldProperty(IVerbatimParagraph['quote'])
+ author = FieldProperty(IVerbatimParagraph['author'])
+ charge = FieldProperty(IVerbatimParagraph['charge'])
+ renderer = FieldProperty(IVerbatimParagraph['renderer'])
+
+
+@utility_config(name=VERBATIM_PARAGRAPH_TYPE, provides=IParagraphFactory)
+class VerbatimParagraphFactory(BaseParagraphFactory):
+ """Verbatim paragraph factory"""
+
+ name = _("Verbatim paragraph")
+ content_type = VerbatimParagraph
+ secondary_menu = True
+
+
+@adapter_config(context=IVerbatimParagraph, provides=IContentChecker)
+class VerbatimParagraphContentChecker(BaseParagraphContentChecker):
+ """Verbatim paragraph content checker"""
+
+ def inner_check(self, request):
+ output = []
+ translate = request.localizer.translate
+ manager = get_parent(self.context, II18nManager)
+ if manager is not None:
+ langs = manager.get_languages()
+ else:
+ negotiator = get_utility(INegotiator)
+ langs = (negotiator.server_language, )
+ i18n = II18n(self.context)
+ for lang in langs:
+ for attr in ('title', 'quote', 'charge'):
+ value = i18n.get_attribute(attr, lang, request)
+ if not value:
+ field_title = translate(IVerbatimParagraph[attr].title)
+ if len(langs) == 1:
+ output.append(translate(MISSING_VALUE).format(field=field_title))
+ else:
+ output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang))
+ for attr in ('author', ):
+ value = getattr(self.context, attr, None)
+ if not value:
+ field_title = translate(IVerbatimParagraph[attr].title)
+ output.append(translate(MISSING_VALUE).format(field=field_title))
+ return output
+
+
+@vocabulary_config(name=VERBATIM_PARAGRAPH_RENDERERS)
+class VerbatimParagraphRendererVocabulary(SimpleVocabulary):
+ """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)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/paragraph/zmi/verbatim.py Wed Mar 07 14:46:15 2018 +0100
@@ -0,0 +1,164 @@
+#
+# 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.association.zmi.interfaces import IAssociationsParentForm
+from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \
+ IParagraphPreview
+from pyams_content.component.paragraph.interfaces.verbatim import IVerbatimParagraph, VERBATIM_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, IEditFormButtons
+from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
+from pyams_skin.layer import IPyAMSLayer
+from pyams_zmi.interfaces import IPropertiesEditForm
+from z3c.form.interfaces import INPUT_MODE
+
+# import packages
+from pyams_content.component.paragraph.verbatim import VerbatimParagraph
+from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
+ BaseParagraphAddMenu, BaseParagraphPropertiesEditForm
+from pyams_content.features.renderer.zmi import BaseRenderedContentPreview
+from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_utils.adapter import adapter_config
+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
+from zope.interface import implementer
+
+from pyams_content import _
+
+
+#
+# Verbatim paragraph
+#
+
+@viewlet_config(name='add-verbatim-paragraph.menu', context=IParagraphContainerTarget, view=IParagraphContainerView,
+ layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=600)
+class VerbatimParagraphAddMenu(BaseParagraphAddMenu):
+ """Verbatim paragraph add menu"""
+
+ label = _("Verbatim...")
+ label_css_class = 'fa fa-fw fa-quote-right'
+ url = 'add-verbatim-paragraph.html'
+ paragraph_type = VERBATIM_PARAGRAPH_TYPE
+
+
+@pagelet_config(name='add-verbatim-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION)
+class VerbatimParagraphAddForm(AdminDialogAddForm):
+ """Verbatim paragraph add form"""
+
+ legend = _("Add new verbatim paragraph")
+ icon_css_class = 'fa fa-fw fa-quote-right'
+
+ fields = field.Fields(IVerbatimParagraph).omit('__parent__', '__name__', 'visible')
+ ajax_handler = 'add-verbatim-paragraph.json'
+ edit_permission = MANAGE_CONTENT_PERMISSION
+
+ def updateWidgets(self, prefix=None):
+ super(VerbatimParagraphAddForm, self).updateWidgets(prefix)
+ if 'quote' in self.widgets:
+ self.widgets['quote'].widget_css_class = 'textarea'
+
+ def create(self, data):
+ return VerbatimParagraph()
+
+ def add(self, object):
+ IParagraphContainer(self.context).append(object)
+
+
+@view_config(name='add-verbatim-paragraph.json', context=IParagraphContainerTarget, request_type=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
+class VerbatimParagraphAJAXAddForm(BaseParagraphAJAXAddForm, VerbatimParagraphAddForm):
+ """Verbatim paragraph add form, JSON renderer"""
+
+
+@pagelet_config(name='properties.html', context=IVerbatimParagraph, layer=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION)
+class VerbatimParagraphPropertiesEditForm(BaseParagraphPropertiesEditForm):
+ """Verbatim paragraph properties edit form"""
+
+ legend = _("Edit verbatim paragraph properties")
+ icon_css_class = 'fa fa-fw fa-quote-right'
+
+ fields = field.Fields(IVerbatimParagraph).omit('__parent__', '__name__', 'visible')
+ fields['renderer'].widgetFactory = RendererFieldWidget
+
+ ajax_handler = 'properties.json'
+ edit_permission = MANAGE_CONTENT_PERMISSION
+
+ def updateWidgets(self, prefix=None):
+ super(VerbatimParagraphPropertiesEditForm, self).updateWidgets(prefix)
+ if 'quote' in self.widgets:
+ self.widgets['quote'].widget_css_class = 'textarea'
+
+
+@view_config(name='properties.json', context=IVerbatimParagraph, request_type=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
+class VerbatimParagraphPropertiesAJAXEditForm(BaseParagraphAJAXEditForm, VerbatimParagraphPropertiesEditForm):
+ """Verbatim paragraph properties edit form, JSON renderer"""
+
+
+@adapter_config(context=(IVerbatimParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
+@implementer(IInnerForm, IPropertiesEditForm, IAssociationsParentForm)
+class VerbatimParagraphInnerEditForm(VerbatimParagraphPropertiesEditForm):
+ """Verbatim paragraph inner edit form"""
+
+ legend = None
+ ajax_handler = 'inner-properties.json'
+
+ @property
+ def buttons(self):
+ if self.mode == INPUT_MODE:
+ return button.Buttons(IEditFormButtons)
+ else:
+ return button.Buttons()
+
+
+@view_config(name='inner-properties.json', context=IVerbatimParagraph, request_type=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
+class VerbatimParagraphInnerAJAXEditForm(BaseParagraphAJAXEditForm, VerbatimParagraphInnerEditForm):
+ """Verbatim paragraph inner edit form, JSON renderer"""
+
+ def get_ajax_output(self, changes):
+ output = super(VerbatimParagraphInnerAJAXEditForm, self).get_ajax_output(changes)
+ if 'renderer' in changes.get(IVerbatimParagraph, ()):
+ form = VerbatimParagraphInnerEditForm(self.context, self.request)
+ form.update()
+ output.setdefault('events', []).append({
+ 'event': 'myams.refresh',
+ 'options': {
+ 'object_id': '{0}_{1}_{2}'.format(
+ self.context.__class__.__name__,
+ getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
+ form.id),
+ 'content': form.render()
+ }
+ })
+ return output
+
+
+#
+# Verbatim paragraph preview
+#
+
+@adapter_config(context=(IVerbatimParagraph, IPyAMSLayer), provides=IParagraphPreview)
+class VerbatimParagraphPreview(BaseRenderedContentPreview):
+ """Verbatim paragraph preview"""