I'm writing a plone.restapi endpoint service and I want to receive parameters in the request. These parameters can be described by an Interface, it's actually INavigationPortlet. So, my question is: how can I use the Interface schema to convert the values from the request form to a python object matching that schema?
I've progressed a bit more, here's something along the lines of what I was looking for:
from zope.schema.interfaces import IFromUnicode
def extract_data(schema, raw_data, prefix):
data = {}
for name in schema.names():
field = schema[name]
raw_value = raw_data.get(prefix + name, field.default)
value = IFromUnicode(field).fromUnicode(raw_value)
data[name] = value
return data
# and calling it like:
data = extract_data(INavigationPortlet, self.request.form, prefix)