zopyx
(Andreas Jung)
December 10, 2018, 11:01am
1
Inside a browser view I create an EasyForm
form instance and I need to set some mailer configurations like
def create_mh(self):
form = plone.api.content.create(type='EasyForm', ...)
mailer = get_actions(form)['mailer']
mailer.to_field = 'email'
mailer.bcc_recipients = 'foo@bar.de'
return 'DONE'
The form instance is correctly correctly however the mailer settings are not assigned.
Anything missing here?
tmassman
(Thomas Massmann #BlackLivesMatter)
December 10, 2018, 11:19am
2
We are doing the same but use the fields_model
and actions_model
which works perfectly.
new = api.content.create(
type='EasyForm',
...
fields_model=CONTACT_FORM_MODEL,
actions_model=CONTACT_FORM_ACTIONS.format(
email=my_custom_email,
),
)
zopyx
(Andreas Jung)
December 10, 2018, 11:38am
3
I am aware that actions_model
takes a supermodel like
<model xmlns:easyform="http://namespaces.plone.org/supermodel/easyform" xmlns:form="http://namespaces.plone.org/supermodel/form" xmlns:i18n="http://xml.zope.org/namespaces/i18n" xmlns:lingua="http://namespaces.plone.org/supermodel/lingua" xmlns:marshal="http://namespaces.plone.org/supermodel/marshal" xmlns:security="http://namespaces.plone.org/supermodel/security" xmlns:users="http://namespaces.plone.org/supermodel/users" xmlns="http://namespaces.plone.org/supermodel/schema">
<schema>
<field name="mailer" type="collective.easyform.actions.Mailer">
<description>E-Mails Form Input</description>
<replyto_field>replyto</replyto_field>
<subject_field>topic</subject_field>
<title>Mailer</title>
</field>
<field name="xxxxxx" type="collective.easyform.actions.SaveData">
<description/>
<title>xxx</title>
</field>
</schema>
</model>
This is used here to define a mailer and a save adapter but the supermodel itself does not specify a particular configuration.
tmassman
(Thomas Massmann #BlackLivesMatter)
December 10, 2018, 12:28pm
4
In your example you wanted to change the to_field
and bcc_recipients
which can be done:
<model xmlns:easyform="http://namespaces.plone.org/supermodel/easyform" xmlns:form="http://namespaces.plone.org/supermodel/form" xmlns:i18n="http://xml.zope.org/namespaces/i18n" xmlns:lingua="http://namespaces.plone.org/supermodel/lingua" xmlns:marshal="http://namespaces.plone.org/supermodel/marshal" xmlns:security="http://namespaces.plone.org/supermodel/security" xmlns:users="http://namespaces.plone.org/supermodel/users" xmlns="http://namespaces.plone.org/supermodel/schema">
<schema>
<field name="mailer" type="collective.easyform.actions.Mailer">
<bcc_recipients>foo@example.com
bar@example.com</bcc_recipients>
<body_footer/>
<body_post/>
<body_pre/>
<body_pt><html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal">
<head><title></title></head>
<body>
<p tal:content="structure body_pre | nothing" />
<dl>
<tal:block repeat="field data | nothing">
<dt tal:content="python:fields[field]" />
<dd tal:content="structure python:widgets[field]" />
</tal:block>
</dl>
<p tal:content="structure body_post | nothing" />
<p tal:content="structure body_footer | nothing" />
</body>
</html></body_pt>
<description>Kontaktformular</description>
<msg_subject>Kontaktformular</msg_subject>
<recipient_email>info@example.com</recipient_email>
<recipient_name>Example Recipient</recipient_name>
<replyto_field>replyto</replyto_field>
<showFields/>
<title>Mailer</title>
<to_field>replyto</to_field>
</field>
</schema>
</model>
1 Like
zopyx
(Andreas Jung)
December 10, 2018, 5:23pm
5
Got it..but it is weird that you can only set the configuration using the XML model..the persistence problem on the Python is strange
alert
(Alessandro Pisa)
December 10, 2018, 9:11pm
6
Just a suspect because I do not know the internals of easyform, but maybe mayler is just a default value not bound to any object and thus modifying it will not trigger a write in the ZODB.
I have already seen this issue in dx schemas.
Let's say you have a field 'people' Choice(..., default=[]), whenever you do:
obj.people.append('johndoe')
you will trigger no write in the ZODB is obj.people in not yet an attribute of obj and if you do not set obj._p_changed=1.
Hope that this can help.
zopyx
(Andreas Jung)
December 11, 2018, 7:46am
7
alert:
Just a suspect because I do not know the internals of easyform, but maybe mayler is just a default value not bound to any object and thus modifying it will not trigger a write in the ZODB.
I have already seen this issue in dx schemas.
Let's say you have a field 'people' Choice(..., default= ), whenever you do:
obj.people.append('johndoe')
you will trigger no write in the ZODB is obj.people in not yet an attribute of obj and if you do not set obj._p_changed=1.
Hope that this can help.
I checked of course the internals and tried the ZODB magic...but it did not help...anyway...generating the actions_field
XML model from a template solved the issue of our purposes.
zopyx
(Andreas Jung)
December 11, 2018, 7:47am
8
Thanks, generating the XML from a template solved the problem.