Managed to get it fixed..  was missing a @deffered and needed a nested
function :)

On 19 July 2011 18:06, Richie Ward <[email protected]> wrote:
> Ok, Will do my best to explain this but reply if your confused :)
>
> I have written a validator that checks the contents of an uploaded
> file. It needs the contents of the file itself and the bind arguments
> ( kw.get("blah") ) to validate the file.
>
> Problem is that I can only seem to get the contents of the file and I
> cant see any way to access the bind arguments.
>
> Here is my code for the validator: (I tacked kw=None onto the
> functions arguments to show what I need it to do)
> def valid_source_file(node, value, kw=None): # Fix Me
>    """ checks to make sure uploaded file is a valid zip """
>    # I cannot find kw anywhere and I need the file object that value returns
>    # List of files and folders that the zip should contain
>    req_file_folder = kw.get("req_file_folder")
>    try:
>        z = zipfile.ZipFile(value['fp'])
>        count = 0
>        namelist = z.namelist()
>        # Loop through files in required files and folders.
>        for item in req_file_folder:
>            # Make sure they are in the zip
>            if item in namelist:
>                count += 1
>        # If they are not all there, then...
>        if not count == len(req_file_folder):
>            # Make a list of files and folders for the Invalid exception
>            filelist = ""
>            for item in req_file_folder:
>                filelist += "%s, " % item
>            filelist = filelist[:-2]
>            raise Invalid(node,
>                'The zip must have the following files: %s' % filelist)
>    except zipfile.BadZipfile:
>        raise Invalid(node, 'The uploaded file is not a zip.')
>
> Its passing through the file object but I just see no way of getting
> the kw / bind arguments.
>
> Sorry if its a little ugly, I plan on cleaning up later :)
>
> --
> Thanks, Richie Ward
>



-- 
Thanks, Richie Ward

-- 
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?hl=en.

Reply via email to