AW: AW: [Zope-dev] z3c.form: unicode error with upload form

2008-03-07 Thread Roger Ineichen
Hi Christophe

> Betreff: Re: AW: [Zope-dev] z3c.form: unicode error with upload form

[...]

> > I guess I know what you are trying to do.
> > As I implemented this widget I was thinking that a file 
> upload never 
> > get used for representation. Becaues it allways offers only upload 
> > again if already an uploaded file exists.
> 
> I've just an image object, that I want to upload:
> 
> class ThumbnailImageEdit(EditForm):
>  fields = Fields(IImage).select('data')
> (...)
> 
> So it wants to display the 'data' field, and fails. Actually 
> not displaying anything is a reasonable default option but it 
> should not fail. This really should be as simple as the 
> formlib for such simple cases, without having to select a 
> particular widget. An advanced default option would be to 
> display the image beside the upload field, but it may be 
> difficult to find a decent layout.
> 
> Christophe

I think the problem is more deep in the implementation.
If we use a binary field we will get a generic upload 
implementation. What I think is the right way to do is
to implement a IImage or ITextFile field. Such fields
whould allow us to implement the correct widget, converter 
and validators.

If you need to allow upload any type of file, some 
generic mime type sniffer and probably a special converter
is needed.

Do you have an idea how such a generic widget should work?
Probably the concept offered in z3c.filetype could be usefull
for a better solution. Any hints are welcome!


Regards
Roger Ineichen
_
END OF MESSAGE

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: AW: [Zope-dev] z3c.form: unicode error with upload form

2008-03-07 Thread Christophe Combelles

Roger Ineichen a écrit :

Hi Christophe


Betreff: [Zope-dev] z3c.form: unicode error with upload form

Hi,

The z3c.form.converter.FileUploadDataConverter has no 
toWidgetValue() method.
Instead, it inherits from BaseDataConverter.toWidgetValue(), 
that returns unicode(data).


However unicode(value) returns an error when the value is binary data!

Shouldn't FileUploadDataConverter implement its own toWidgetValue?


I guess I know what you are trying to do.
As I implemented this widget I was thinking that a file upload never get
used for representation. Becaues it allways offers only upload again
if already an uploaded file exists.


I've just an image object, that I want to upload:

class ThumbnailImageEdit(EditForm):
fields = Fields(IImage).select('data')
(...)

So it wants to display the 'data' field, and fails. Actually not displaying 
anything is a reasonable default option but it should not fail. This really 
should be as simple as the formlib for such simple cases, without having to 
select a particular widget. An advanced default option would be to display the 
image beside the upload field, but it may be difficult to find a decent layout.


Christophe




And the converter is only designed for upload files and not for convert 
them to widget output. Because the converter is registered for the 
upload widget which never should represent the content.


This means you have to use a own widget for represent a file 
content if it's text. And for this widget you can use another

custom converter. But sure I could be wrong. Do you see anything
which is wrong with that?

Now I guess, you are uesing the IFileWidget for your custom
widget implementation and this doesn't work, right?

See also my commit message in revision 76629:


Changed registration of file upload data converter.
Register FileUploadDataConverter for IBytes/IFileWidget.
This will force to use the data converter only for IFileWidget
and not for IBytes at all. IBytes/IWidget uses by default the
FieldDataConverter.

Added tests

Note:
The default widget for IBytes is the IFileWidget.

What does this mean:
If you need to use a text area widget for IBytes, you have to
register a custom widget in the form because the default widget
for IBytes is a file upload widget. You can do this by simply
set ``fields['foobar'].widgetFactory = TextWidget``.
-

Does this make sense to you?

Any hintes and improvments are very welcome.

Regards
Roger Ineichen


Christophe






___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope )


AW: [Zope-dev] z3c.form: unicode error with upload form

2008-03-05 Thread Roger Ineichen
Hi Christophe

> Betreff: [Zope-dev] z3c.form: unicode error with upload form
> 
> Hi,
> 
> The z3c.form.converter.FileUploadDataConverter has no 
> toWidgetValue() method.
> Instead, it inherits from BaseDataConverter.toWidgetValue(), 
> that returns unicode(data).
> 
> However unicode(value) returns an error when the value is binary data!
> 
> Shouldn't FileUploadDataConverter implement its own toWidgetValue?

I guess I know what you are trying to do.
As I implemented this widget I was thinking that a file upload never get
used for representation. Becaues it allways offers only upload again
if already an uploaded file exists.

And the converter is only designed for upload files and not for convert 
them to widget output. Because the converter is registered for the 
upload widget which never should represent the content.

This means you have to use a own widget for represent a file 
content if it's text. And for this widget you can use another
custom converter. But sure I could be wrong. Do you see anything
which is wrong with that?

Now I guess, you are uesing the IFileWidget for your custom
widget implementation and this doesn't work, right?

See also my commit message in revision 76629:


Changed registration of file upload data converter.
Register FileUploadDataConverter for IBytes/IFileWidget.
This will force to use the data converter only for IFileWidget
and not for IBytes at all. IBytes/IWidget uses by default the
FieldDataConverter.

Added tests

Note:
The default widget for IBytes is the IFileWidget.

What does this mean:
If you need to use a text area widget for IBytes, you have to
register a custom widget in the form because the default widget
for IBytes is a file upload widget. You can do this by simply
set ``fields['foobar'].widgetFactory = TextWidget``.
-

Does this make sense to you?

Any hintes and improvments are very welcome.

Regards
Roger Ineichen

> Christophe

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )