This one time, at band camp, Ian Bicking wrote:
>
>Jamie Wilkinson wrote:
>> Hey,
>> 
>> Does anyone have an example of using FormEncode's
>> FieldStorageUploadConverter or FileUploadKeepr ?  There's no example in the
>> docstrings and I'm just having a hard time applying them in the same way as
>> any of the other validators.
>
>I've used them from times (I guess I must have written at least one of 
>them).  They might be from FunFormKit days, and I might have used them 
>only modestly since then.  FileStorageUploadConverter just converts any 
>spurious FileStorage values you might have in your request into strings. 
>  Which probably isn't what you want to do in nearly any situation.
>
>FileUploadKeeper saves the file to disk, and then if the rest of the 
>submission fails and you have to resubmit the content it'll give you a 
>hidden field that can take the place of re-uploading the file.  Anyway, 
>it's meant to be used in a situation where you have a complex form and 
>an image upload in that form.

Ok.

I've got a bug where I try to validate a form with a file upload, and on
formencode/validators.py line 1450 it throws an AttributeError; the
cgi.FieldStorage doesn't have an attribute 'get'.

This is unexpected, because the docstring for FileUploadKeeper is pretty
clear that it handles both text and cgi.FieldStorage uploads.

(Incidentally, if I pass in a string to the form from with my paste.fixture
test app, then it also blows up saying 'str object has no attribute get'.)

Should something other than the cgi.FieldStorage be passed in as the value
to be validated here?

I guess I'm calling it wrong, but I'm not sure how to do it right.  The
schema at the moment looks like this:

class BaseSchema(schema.Schema):
    allow_extra_fields = True
    filter_extra_fields = True

    def validate(self, input):
        try:
            result = self.to_python(input)
            return result, {}
        except Invalid, e:
            return {}, e.unpack_errors()

class NewProposalSchema(BaseSchema):
        attachment = FileUploadKeeper()

and is called like:

defaults = dict(request.POST)
if defaults:
    results, errors = NewProposalSchema().validate(defaults)

(if you've seen Ben's crud module, you'll recognise the pattern)

Any hints or examples on using FileUploadKeeper in the wild would be greatly
appreciated.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss
-~----------~----~----~----~------~----~------~--~---

Reply via email to