# HG changeset patch # User Thierry Florac # Date 1567606210 -7200 # Node ID 07781aca5cd77238722a30708815ba75c3e904a6 # Parent 9b9c178bcf87c2fc9d0a6b6d069ed84ce89e17be Updated shared forms rendering (using new paragraph type) diff -r 9b9c178bcf87 -r 07781aca5cd7 src/pyams_default_theme/shared/form/__init__.py --- a/src/pyams_default_theme/shared/form/__init__.py Wed Sep 04 16:07:32 2019 +0200 +++ b/src/pyams_default_theme/shared/form/__init__.py Wed Sep 04 16:10:10 2019 +0200 @@ -17,10 +17,9 @@ from zope.interface import Interface, Invalid from zope.schema import TextLine -from pyams_content.features.renderer.interfaces import ISharedContentRenderer from pyams_content.shared.form import IFormFieldContainer, IFormFieldContainerTarget, IWfForm from pyams_default_theme.component.paragraph.interfaces import IParagraphContainerPortletRenderer -from pyams_default_theme.features.renderer import BaseContentRenderer +from pyams_default_theme.interfaces import IContentTitle from pyams_default_theme.layer import IPyAMSDefaultLayer from pyams_form.form import AddForm from pyams_form.help import FormHelp @@ -48,6 +47,14 @@ INVALID_TOKEN_ERROR = _("Can't verify recaptcha token! Are you a robot?") +@adapter_config(context=(IWfForm, IPyAMSDefaultLayer), provides=IContentTitle) +def form_title_adapter(context, request): + """Form title adapter""" + i18n = II18n(context) + return i18n.query_attribute('alt_title', request=request) or \ + i18n.query_attribute('title', request=request) + + class FormFieldContainerInputForm(AddForm): """Form fields container display form""" @@ -161,26 +168,6 @@ return Viewlet.__new__(cls) -@adapter_config(name='form-render', context=(IFormFieldContainerTarget, IPyAMSLayer), - provides=ISharedContentRenderer) -class FormFieldContainerRenderer(BaseContentRenderer): - """Form field container renderer""" - - weight = 20 - input_form = None - - def __init__(self, context, request): - super(FormFieldContainerRenderer, self).__init__(context, request) - self.input_form = FormFieldContainerInputForm(context, self.request) - - def update(self): - super(FormFieldContainerRenderer, self).update() - self.input_form.update() - - def render(self): - return self.input_form.render() - - @pagelet_config(name='submit.html', context=IWfForm, layer=IPyAMSDefaultLayer) class FormSubmitPage(PortalContextIndexPage): """Form submit page""" diff -r 9b9c178bcf87 -r 07781aca5cd7 src/pyams_default_theme/shared/form/paragraph.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/shared/form/paragraph.py Wed Sep 04 16:10:10 2019 +0200 @@ -0,0 +1,55 @@ +# +# Copyright (c) 2008-2019 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +from pyams_content.features.renderer.interfaces import IContentRenderer +from pyams_content.shared.form import IWfForm +from pyams_content.shared.form.interfaces import IFormFieldsParagraph +from pyams_default_theme.features.renderer import BaseContentRenderer +from pyams_default_theme.shared.form import FormFieldContainerInputForm +from pyams_skin.layer import IPyAMSLayer +from pyams_template.template import template_config +from pyams_utils.adapter import adapter_config +from pyams_utils.traversing import get_parent + + +__docformat__ = 'restructuredtext' + +from pyams_default_theme import _ + + +@adapter_config(name='default', context=(IFormFieldsParagraph, IPyAMSLayer), provides=IContentRenderer) +@template_config(template='templates/form-fields.pt', layer=IPyAMSLayer) +class FormFieldsParagraphDefaultRenderer(BaseContentRenderer): + """Form fields paragraph default renderer""" + + label = _("Default form fields renderer") + weight = 1 + + i18n_context_attrs = ('title', ) + + input_form = None + + def __init__(self, context, request): + super(FormFieldsParagraphDefaultRenderer, self).__init__(context, request) + form = get_parent(context, IWfForm) + if form is not None: + self.input_form = FormFieldContainerInputForm(form, self.request) + + def update(self): + super(FormFieldsParagraphDefaultRenderer, self).update() + if self.input_form is not None: + self.input_form.update() + + def render(self): + if self.input_form is None: + return '' + return super(FormFieldsParagraphDefaultRenderer, self).render() diff -r 9b9c178bcf87 -r 07781aca5cd7 src/pyams_default_theme/shared/form/templates/form-fields.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/shared/form/templates/form-fields.pt Wed Sep 04 16:10:10 2019 +0200 @@ -0,0 +1,2 @@ +

${view.title}

+
${structure:view.input_form.render()}
\ No newline at end of file