Re: [Zope-dev] z3c.form - creating a file upload widget

2009-03-12 Thread Martin Aspeli
Stephan Richter wrote:
> On Thursday 12 March 2009, Martin Aspeli wrote:
>> Could I maybe create a custom validator that checks for a magic
>> constant? If so, how? I have both a custom field (in the zope.schema
>> sense) and a custom widget.
> 
> Yeah. I could swear I implemented this before. A validator is an adapter for 
> the field, widget and more, so creating a special one for your case is no 
> problem at all.
> 
> Actually, did you see the FileUploadDataConverter in converter.py? It does 
> the 
> right thing when no new data was uploaded. It is registered for IBytes and 
> IFileWidget, so if you use a different field and widget interface, it would 
> not be used, but you could use it.

Yes - I have a custom converter based on this. However, it's based on 
the z3c.form 1.x one, I guess. The NOT_CHANGED constant doesn't exist in 
my version. :-/

Martin

-- 
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

___
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: [Zope-dev] z3c.form - creating a file upload widget

2009-03-12 Thread Stephan Richter
On Thursday 12 March 2009, Martin Aspeli wrote:
> Could I maybe create a custom validator that checks for a magic
> constant? If so, how? I have both a custom field (in the zope.schema
> sense) and a custom widget.

Yeah. I could swear I implemented this before. A validator is an adapter for 
the field, widget and more, so creating a special one for your case is no 
problem at all.

Actually, did you see the FileUploadDataConverter in converter.py? It does the 
right thing when no new data was uploaded. It is registered for IBytes and 
IFileWidget, so if you use a different field and widget interface, it would 
not be used, but you could use it.

Regards,
Stephan
-- 
Stephan Richter
Web Software Design, Development and Training
Google me. "Zope Stephan Richter"
___
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: [Zope-dev] z3c.form - creating a file upload widget

2009-03-12 Thread Martin Aspeli
Stephan Richter wrote:
> On Thursday 12 March 2009, Martin Aspeli wrote:
>> I'm writing a custom file widget for z3c.form that works like the
>> Archetypes file widget that Plone uses and the formlib widget in
>> collective.namedfile. That is, after you've uploaded a file once, you're
>> given a radio button to decide whether to upload a new file, or leave
>> the existing file in place.
>>
>> I can't quite figure out how to do this, though. I've tried to override
>> the extract() method on the widget to look in the request for the
>> special marker that says "user chose not to change the file". However, I
>> don't know what to return. If I return NOVALUE, then validation fails
>> (if the field is required). If I try to look up the field value from the
>> data manager and return it, it ends up setting the field back on itself,
>> which is wasteful.
> 
> All great questions and I am not sure I have good answers. I think you want 
> a "NONEWVALUE" or so marker and have the validator honor it correctly.
> 
> If you make a proposal to enrich the API, I'll probably agree to it. :-)

That's good, but I need this by yesterday... ;-)

Could I maybe create a custom validator that checks for a magic 
constant? If so, how? I have both a custom field (in the zope.schema 
sense) and a custom widget.

Martin

-- 
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

___
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: [Zope-dev] z3c.form - creating a file upload widget

2009-03-12 Thread Stephan Richter
On Thursday 12 March 2009, Dan Korostelev wrote:
> Just to note, there's already the NOT_CHANGED constant in
> z3c.form.interfaces.

Yep, good point.

Regards,
Stephan
-- 
Stephan Richter
Web Software Design, Development and Training
Google me. "Zope Stephan Richter"
___
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: [Zope-dev] z3c.form - creating a file upload widget

2009-03-12 Thread Dan Korostelev
2009/3/12 Stephan Richter :
> On Thursday 12 March 2009, Martin Aspeli wrote:
>> I'm writing a custom file widget for z3c.form that works like the
>> Archetypes file widget that Plone uses and the formlib widget in
>> collective.namedfile. That is, after you've uploaded a file once, you're
>> given a radio button to decide whether to upload a new file, or leave
>> the existing file in place.
>>
>> I can't quite figure out how to do this, though. I've tried to override
>> the extract() method on the widget to look in the request for the
>> special marker that says "user chose not to change the file". However, I
>> don't know what to return. If I return NOVALUE, then validation fails
>> (if the field is required). If I try to look up the field value from the
>> data manager and return it, it ends up setting the field back on itself,
>> which is wasteful.
>
> All great questions and I am not sure I have good answers. I think you want
> a "NONEWVALUE" or so marker and have the validator honor it correctly.
>
> If you make a proposal to enrich the API, I'll probably agree to it. :-)

Just to note, there's already the NOT_CHANGED constant in z3c.form.interfaces.

-- 
WBR, Dan Korostelev
___
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: [Zope-dev] z3c.form - creating a file upload widget

2009-03-12 Thread Stephan Richter
On Thursday 12 March 2009, Martin Aspeli wrote:
> I'm writing a custom file widget for z3c.form that works like the
> Archetypes file widget that Plone uses and the formlib widget in
> collective.namedfile. That is, after you've uploaded a file once, you're
> given a radio button to decide whether to upload a new file, or leave
> the existing file in place.
>
> I can't quite figure out how to do this, though. I've tried to override
> the extract() method on the widget to look in the request for the
> special marker that says "user chose not to change the file". However, I
> don't know what to return. If I return NOVALUE, then validation fails
> (if the field is required). If I try to look up the field value from the
> data manager and return it, it ends up setting the field back on itself,
> which is wasteful.

All great questions and I am not sure I have good answers. I think you want 
a "NONEWVALUE" or so marker and have the validator honor it correctly.

If you make a proposal to enrich the API, I'll probably agree to it. :-)

Regards,
Stephan
-- 
Stephan Richter
Web Software Design, Development and Training
Google me. "Zope Stephan Richter"
___
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 )