Changeset 4155

Show
Ignore:
Timestamp:
02/28/08 19:37:47 (9 months ago)
Author:
faide
Message:

Apply Jorge Godoy's patch against our custom FieldStorageConvertor? to allow the field to be optional.
Fixes ticket #1705

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/turbogears/validators.py

    r4106 r4155  
    2121 
    2222from formencode import validators # to disambiguate the Number validator... 
     23 
     24# this import is needed for our custom FieldStorageUploadConverter 
     25import cgi 
    2326 
    2427def _(s): return s # dummy 
     
    134137            return value 
    135138 
     139# see #1464357 on FE bugtracker (http://tinyurl.com/lm9ae). 
     140# Custom version of FieldStorage validator that does not break FE schema validator. 
     141class FieldStorageUploadConverter(TgFancyValidator): 
     142    def __init__(self, *args, **kwargs): 
     143        super(TgFancyValidator, self).__init__(*args, **kwargs) 
     144        self.not_empty = kwargs.get('not_empty') 
     145 
     146    def _to_python(self, value, state=None): 
     147        if isinstance(value, cgi.FieldStorage): 
     148            if value.filename: 
     149                return value 
     150            if self.not_empty: 
     151                raise Invalid('invalid', value, state) 
     152        return value 
     153 
    136154 
    137155# For translated messages that are not wrapped in a Validator.messages