Anybody using collective.pfg.dexterity with Plone 5?

I'm running into errors trying to use collective.pfg.dexterity, not sure if it's because I can't find any directions on how to make this work or if the errors are Plone 5 compatability related.

Had to pin archetypes.referencebrowserwidget = 2.5.7 for buildout. Installed fine as far as I can tell. Not sure how my PFG fields get "mapped" to a dexterity object. Before getting into the errors, I need to start with how to use this addon. Anybody have step by step instructions?

Just tested collective.pfg.dexterity with Plone 4 and now I see how it's supposed to work. I don't know what it will take to make it P5 compatable, but can confirm that right now it isn't. Need to upgrade pin version for archetypes.referencebrowserwidget. Trying to add Content Adapter throwsAttributeError: 'referencebrowser.js' Various other AttributeError: 'NoneType' object has no attribute 'portal_type' errors arose. Filed an issue.

1 Like

a quick look at it show that the package is using the portal_properties tool to store some configuration.

that's must be solvable (moving that configuration into Plone's registry and adding an upgrade step); the main problem for me is the package also depends on Products.DataGridField, which doesn't seem to be compatible with Plone 5 neither...

that's the way it's, and that's why we have been warning about this for almost a year.

now that more and more people are stumbling with the same problems we can start thinking seriously on how to solve pending issues and move on.

Hi, Christina! Have you tried collective.easyform? It's a PloneFormGen clone implemented with the Dexterity framework. We currently have a student funded by Google Summer of Code improving the code so I suggest trying the "improved-mailer-test" branch which is working well with Plone 5. You can download that in your buildout using the mr.developer extension, which may grab addons directly from Github (among other repository origins). You can ping me at IRC or Slack if you need any help with that.

Easyform offers the same "adapter" feature found in PFG, but it's now called "Actions" and can be found in the Toolbar > Actions submenu. From there you should be able to add a Python script that creates new items in the portal when a form is submitted, just like c.pfg.dexterity does. You may still stumble in the outdated documentation issue you created in GitHub, though. Nevertheless imo it's better to have a Dexterity only solution for Plone 5 and leave all Archetypes-based things in the past. You'll get a more future-proof codebase and all the perks of updates and new developments (e.g. the UI coming from plone.schemaeditor you'll find under Toolbar > Actions > Define fields/actions.

Finally, note that "adding items to the site when a form is submitted" could be the definition of Dexterity itself. Point being that you might not need Easyform at all. Depending on your usecase you could create a content type and set permissions/workflow so new items can be added by anonymous or authenticated members and then go through a review process before being made publicly available. Could you tell us about your usecase?

Creating content with plone.api is very easy, so you could add a script form collective.easyform.
Since I had some problems finding docs myself, I include a link to 'how to make a page'

https://github.com/espenmn/medialog.bergensiana/blob/master/medialog/bergensiana/setuphandlers.py#L45

I'm not sure importing plone.api is allowed inside EasyForm's Restricted Python actions.

We can't import RichTextValue from Easyform's action Script, as per @espenmn example, failing with:

from plone.app.textfield.value import RichTextValue
*** Unauthorized: import of 'plone.app.textfield.value' is unauthorized

Otoh we actually can import plone.api. However if we add a script like this:

## Python Script
##bind container=container
##bind context=context
##bind subpath=traverse_subpath
##parameters=fields, easyform, request
##title=
##

from plone import api
api.content.create(
    type='Document',
    container=container,
    title='New object - {}'.format(fields['form.widgets.replyto']),
    description=fields['form.widgets.topic'],
    text=fields['form.widgets.comments']
)

We fail with:

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module Products.PDBDebugMode.runcall, line 70, in pdb_runcall
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.z3cform.layout, line 66, in __call__
  Module plone.z3cform.layout, line 50, in update
  Module collective.easyform.browser.view, line 256, in update
  Module plone.z3cform.fieldsets.extensible, line 59, in update
  Module plone.z3cform.patch, line 30, in GroupForm_update
  Module z3c.form.group, line 145, in update
  Module plone.app.z3cform.csrf, line 21, in execute
  Module z3c.form.action, line 98, in execute
  Module z3c.form.button, line 315, in __call__
  Module z3c.form.button, line 170, in __call__
  Module collective.easyform.browser.view, line 159, in handleSubmit
  Module collective.easyform.browser.view, line 122, in processActions
  Module collective.easyform.actions, line 535, in onSuccess
  Module collective.easyform.actions, line 528, in executeCustomScript
  Module Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 344, in _exec
  Module script, line 4, in d2c
   - <PythonScript at /Plone8/form/d2c>
   - Line 4
Unauthorized: You are not allowed to access 'content' in this context

And then:

2016-06-25 19:01:33 WARNING plone.protect error parsing dom, failure to add csrf token to response for url http://localhost:8080/Plone8/form/view

Inspecting Easyform's <form> I do see the <input name="_authenticator"> so I wonder if we can do anything about the Unauthorized error. I can also insert pdb traces in the Form Action Script and, interestingly, if I manually make the api.content.create call from there, it works.

sorry, I did not test it.
I actually used a browser view (in medialog.lxml) to do it, but that is probably not a good approach here.

Is it that there is a bug in plone.api that it doesn't whitelist itself to be safe to use with restricted python?

Is it a good Idea that plone.api should mock the authentication applied on actions on easyforms ?

Thanks, I will test that and see how it goes.

My use case is unconventional and I know people will scream because I'm trying to make Plone do something maybe it's not meant to do, but I don't care—my editorial team and I want to create a simple form for our staff to use to let us know what content on our sites needs to be updated. The purpose of the form is to give the editorial team some basic information to get started—to serve 1) as a initial conversation/research piece and 2) to act as a "ticket" or in GitHub speak, an "issue" which team members will update and comment on. So I want the form submissions to convert into document/page content types. These will all be in a folder and that will serve as a our work log and tracker.

I think I see what you mean—create new content type that has the fields I want (that would be on the form) and then the users add that. I'll try that, as I'm getting buildout errors with collective.easyform and I'm not too confident using and add-on that is being updated. I'd rather wait until it's fully compatible as I don't have the skills to troubleshoot major errors.

1 Like

that's a perfectly valid use case and is totally doable in Plone; please share your solution if you have success on this.

in case you don't, it's probably time to write an add-on for it.

You can use PFG + uwosh.pfg.d2c: the master is working on Plone 5 well.
On the other hand PloneFormGen has some minor issues with Plone 5, but nothing really blocker.

FWIW, collective.pfg.dexterity >= 1.0.0rc1 should be Plone 5 compatible.

Whenever I have a similar need personally in the future, I'll try to make similar feature for collective.easyform (it should be much simpler, because easyform is already Dexterity and could then trivially support generating form templates directly from Dexterity types, and generating Dexterity types from forms).