PloneFormGen mailer adapter subject override examples?

I haven't been able to locate any examples of override TAL expressions for the PFG mailer adapter. I'd like to have the subject of the email be:

"New sponsor: " + here/organization-name

but I don't see a way to concatenate using non-python: TAL and

python: "New sponsor: " + here['organization-name']

results in TypeError: cannot concatenate 'str' and 'Acquisition.ImplicitAcquisitionWrapper' objects

because the latter expression is actually an FGStringField, and

python: "New sponsor: " + (here['organization-name'])()

results in

  Module Products.PloneFormGen.content.thanksPage, line 233, in displayInputs
AttributeError: _getFieldObjects

 - Expression: "python:here.displayInputs(request)"
 - Filename:   ... ormGen/skins/PloneFormGen/fg_thankspage_embedded_view.pt
 - Location:   (line 13: col 39)
 - Source:     ... :define="fields python:here.displayInputs(request)"
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Arguments:  repeat: {...} (0)
               template: <ImplicitAcquisitionWrapper fg_thankspage_view_p3 at 0x7ffb0bbca4b0>
               modules: <instance - at 0x7ffb2a8f2fc8>
               here: <ImplicitAcquisitionWrapper thank-you at 0x7ffb0bbcae60>
               user: <ImplicitAcquisitionWrapper - at 0x7ffb0bb04190>
               nothing: <NoneType - at 0x91a870>
               container: <ImplicitAcquisitionWrapper thank-you at 0x7ffb0bbcae60>
               default: <object - at 0x7ffb32d10590>
               request: <instance - at 0x7ffb0ac06170>
               wrapped_repeat: <SafeMapping - at 0x7ffb0ac33af8>
               traverse_subpath: <list - at 0x7ffb0a0b05a8>
               loop: {...} (0)
               context: <ImplicitAcquisitionWrapper thank-you at 0x7ffb0bbcae60>
               translate: <function translate at 0x7ffb0a61c0c8>
               root: <ImplicitAcquisitionWrapper Zope at 0x7ffb12227910>
               options: {...} (1)
               target_language: <NoneType - at 0x91a870>

Even the very simple expression here/organization-name results in the same error stack trace.

When I stepped through displayInputs it seems that self is the string field instead of (when there is no override expression) being the form folder.

If here['organization-name'] is a field, you may be able to get the value with something like here['organization-name'].get(here).

1 Like

If 'organization-name' is an attribute of an object, not a key in a dictionary, try getattr: getattr(here, 'organization-name')

Also ... don't forget the "string:" semantics in TALES: "string: New sponsor: ${here/organization-name}".

1 Like

Thanks guys!

organization-name is the ID of the PFG string field

python: "New sponsor: " + here['organization-name'].get(here)

and

python: "New sponsor: " + (here['organization-name']).get(here)

(wrapped in parens, just in case) both result in:

TypeError: cannot concatenate 'str' and 'NoneType' objects

while

string: New sponsor: ${here/organization-name}

results in that same trace inside displayInputs():

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
  Module Products.CMFFormController.BaseControllerPageTemplate, line 29, in _call
  Module Products.CMFFormController.ControllerBase, line 232, in getNext
  Module Products.CMFFormController.Actions.TraverseTo, line 38, in __call__
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module Products.CMFDynamicViewFTI.browserdefault, line 70, in __call__
  Module Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.CMFCore.FSPageTemplate, line 237, in _exec
  Module Products.CMFCore.FSPageTemplate, line 177, in pt_render
  Module Products.PageTemplates.PageTemplate, line 87, in pt_render
  Module zope.pagetemplate.pagetemplate, line 132, in pt_render
  Module five.pt.engine, line 98, in __call__
  Module z3c.pt.pagetemplate, line 163, in render
  Module chameleon.zpt.template, line 261, in render
  Module chameleon.template, line 191, in render
  Module chameleon.template, line 171, in render
  Module d286f08c87556ef6f99684f852b90857.py, line 182, in render
  Module 9451d21d79a4b53941d9d685aea8d21e.py, line 1223, in render_master
  Module 9451d21d79a4b53941d9d685aea8d21e.py, line 420, in render_content
  Module d286f08c87556ef6f99684f852b90857.py, line 170, in __fill_content_core
  Module d286f08c87556ef6f99684f852b90857.py, line 93, in render_content_core
  Module 7be137901df6235199011e94e224df7d.py, line 156, in render_content_core
  Module Products.PloneFormGen.content.thanksPage, line 233, in displayInputs
AttributeError: _getFieldObjects

 - Expression: "python:here.displayInputs(request)"
 - Filename:   ... ormGen/skins/PloneFormGen/fg_thankspage_embedded_view.pt
 - Location:   (line 13: col 39)
 - Source:     ... :define="fields python:here.displayInputs(request)"
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Arguments:  repeat: {...} (0)
               template: <ImplicitAcquisitionWrapper fg_thankspage_view_p3 at 0x7ffb0a6b0550>
               modules: <instance - at 0x7ffb2a8f2fc8>
               here: <ImplicitAcquisitionWrapper thank-you at 0x7ffb0a6b0230>
               user: <ImplicitAcquisitionWrapper - at 0x7ffb0a7deb90>
               nothing: <NoneType - at 0x91a870>
               container: <ImplicitAcquisitionWrapper thank-you at 0x7ffb0a6b0230>
               default: <object - at 0x7ffb32d10590>
               request: <instance - at 0x7ffb0a0c84d0>
               wrapped_repeat: <SafeMapping - at 0x7ffb0a5a9e68>
               traverse_subpath: <list - at 0x7ffb09fdfc68>
               loop: {...} (0)
               context: <ImplicitAcquisitionWrapper thank-you at 0x7ffb0a6b0230>
               translate: <function translate at 0x7ffb0a44c1b8>
               root: <ImplicitAcquisitionWrapper Zope at 0x7ffb1005f960>
               options: {...} (1)
               target_language: <NoneType - at 0x91a870>

This is Products.PloneFormGen 1.8.1 and Plone 5.0.8

Are you sure og is the syntax. I think you just dont get the fields

Tåken from memory: I though it was:

Request.form.fieldname

1 Like

Kisses all around! That was the answer :slight_smile:

string: New sponsor: ${request/form/organization-name}

and

python: "New sponsor: " + request.form['organization-name']

worked. I am going to add this to the PFG docs. I could have sworn I'd seen examples of this before (specifically the request/form construct).

I wasn't aware of this syntax... but it makes sense – it's chameleon, isn't it? Old dog, new tricks, etc.