[Zope3-Users] z3c.form image upload widget

Roger Ineichen dev at projekt01.ch
Fri Mar 6 07:39:39 EST 2009


Hi Mrtin

> Betreff: [Zope3-Users] z3c.form image upload widget
> 
> Hi,
> 
> I'm in need of a z3c.form form that supports image uploads. 
> Ideally, it should support optional and mandatory fields, and 
> in 'edit' mode it should allow the user to either keep the 
> current image or replace it with a new one (Plone/Archetypes 
> has a radio button + a file upload widget to achieve this). 
> It'd be nice to also show an icon of filetype or small 
> thumbnail of the image next to the widget. Finally, it needs 
> to retain the filename that is sent in the request and store 
> this somewhere.
> 
> Does anything like this exist? We have collective.namedfile 
> for Zope 2 and formlib, and we could probably borrow some 
> things from that, but it'd be nice if there was something 
> already. Note that for z3c.form on Zope 2, with the 
> plone.z3cform library, you get a "wrapper" around the form 
> that makes it behave very much like it does in Zope 3. We may 
> need a custom data manager for the image, and maybe a custom 
> image IField type, but it should be easy enough to re-use 
> most of the stuff across Zope 2 and Zope 3.

I think everything should be there for a simple file upload.
The z3c.form doesn't have enhanced upload features.

One way to implement an object replacement whould be to
ad an addditional field (bool) in the object schema
and depneding on that input replace the file in the
EditForm.applyChanges method.

If this replace-me field is a part of the archetype file,
then a new widget whould be the right thing.

btw, the default z3c.form widget returns the bytes data
as widget value in applyChanges based on the converters
convertion. Probably an archtype file widget should return
an archetype? But this depends on the type of schema field
which is used.

In general I can say, if a widget is based on IBytes the widget
and converter must return bytes and if an e.g. archetype field
requires an IArchtypeField object, the widget/converter must
return such an object. In the case a schema field defines IBytes
the data given from te widget must get applied to the file in
the edit forms action method e.g. applyChanges. And if a file
upload depends on a IObject schema field with IFile as schema,
the widget/converter must return an IFile object and you can just
apply the given value in applyChanges to the context.

Hope that helss a little bit.

source:
z3c.form.browser.file.FileFieldWidget
z3c.form.converter.FileUploadDataConverter

Regards
Roger Ineichen
_____________________________
END OF MESSAGE


> Cheers,
> Martin
> 
> --
> Author of `Professional Plone Development`, a book for 
> developers who want to work with Plone. See 
> http://martinaspeli.net/plone-book
> 
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
> 



More information about the Zope3-users mailing list