[Zope3-Users] Fields for file and images
Johan Carlsson
johanc at easypublisher.com
Tue Oct 25 05:54:04 EDT 2005
James Allwyn wrote:
> I too have been getting "UnpickleableError" while playing with ObjectWidgets.
Hi James,
What I ended up doing was to move the removeSecurityProxy from the
Content Type Class to the Browser View (where I think it belongs).
(In my case this would be an overriden version of ObjectWidget)
The method applyChanges was override ang changed to include the
removeSecurityProxy. (see below)
For your example you would have to create a PersonWidget and a
PageWidget (copy the applyChanges from ObjectWidget and change
so the security is removed before saving).
(The classes might end-up looking the same, som maybe you only
need one?)
But I'm now suspecting the real problem is due to a misconfiguration
in ZCML. I'll let you know what I find out.
Regards,
johan
class FileWidget(ObjectWidget):
def applyChanges(self, content):
field = self.context
# create our new object value
value = field.query(content, None)
if value is None:
# TODO: ObjectCreatedEvent here would be nice
value = self.factory()
# apply sub changes, see if there *are* any changes
# TODO: ObjectModifiedEvent here would be nice
changes = applyWidgetsChanges(self, field.schema, target=value,
names=self.names)
# if there's changes, then store the new value on the content
if changes:
file=removeSecurityProxy(value)
form = self.request.form
filename = getattr(form["field.file.data"], "filename", None)
contenttype = form.get("field.file.contentType")
if filename:
if not contenttype:
contenttype =
content_types.guess_content_type(filename)[0]
file.contentType=contenttype
#descriptor = objectevent.Attributes(IFile, "contentType")
#descriptor.attributes += "data"
#event = objectevent.ObjectModifiedEvent(file, descriptor)
#zope.event.notify(event)
field.set(content, file)
return changes
fw = CustomWidgetFactory(FileWidget, File )
--
Johan Carlsson Tel: + 46 8 31 24 94
Colliberty Mob: + 46 70 558 25 24
Torsgatan 72 Email: johanc at easypublisher.com
SE-113 37 STOCKHOLM
More information about the Zope3-users
mailing list