Happy holidays Plone folks... It is in early development, and still needs some more tests, but I have put together a computed field type in an add-on for zope.schema in a Plone context.
This should work in Dexterity, however any add-on using this is responsible for actually hooking up event subscribers needed to use it (my team is using this in non-content forms).
Particulars:
- Given a context, field has compute() method that generates a floating-point field value based on one of two configurations:
- Stock function (e.g. sum, average, ratio) applied to values of 1..* other fields in same schema, listed in order.
- A named adapter that acts as a factory for computation.
- Works with plone.supermodel and plone.schemaeditor.
- Present limitations:
- Tests only about 50% complete, and package has only been used yet in Plone 4.x context.
- Does not yet support any nesting of computation.
- Assumes fields in same schema, insofar as zope.schema.getFieldsInOrder() is concerned; behavior support is not assumed yet.
- Requires installation as add-on (profile) to install a tiny JS shim to make plone.schemaeditor (1.4.x Plone 4.x) overlays play nice with z3c.form's orderedselect_input.js used in selecting/ordering source fields. My hope is to remove this need in Plone 5 context.
- Support for non-float results not assumed yet.
- Monkey-patches plone.autoform to exempt plone.schemaeditor listing from omitting the field from editing. I may revisit this, but this was a tricky problem to get around.
Once I get back from my holiday vacation plans, I will work toward Plone 5 testing and an early January release, should anyone find this useful.
Sean