1. William Wu
  2. pyramid_wtf

Commits

William Wu  committed d8ff270

Clean up namespace

  • Participants
  • Parent commits fdce9cc
  • Branches default

Comments (0)

Files changed (2)

File pyramid_wtf/fields.py

View file
  • Ignore whitespace
-from . import widgets
+from . import widgets as _widgets
 from wtforms.fields import *
 
 _FileField = FileField
     '''
     自訂配合 pyramid 使用的 FileField 類別,可接受多個檔案上傳
     '''
-    widget = widgets.MultiFilesInput()
+    widget = _widgets.MultiFilesInput()
 
     def process_formdata(self, valuelist):
         self.data = valuelist

File pyramid_wtf/validators.py

View file
  • Ignore whitespace
+import wtforms
+from cgi import FieldStorage
 from wtforms.validators import *
+from wtforms.validators import StopValidation, ValidationError
+
+__all__ = wtforms.validators.__all__ + ['StopValidation', 'ValidationError', 'FileRequired', 'FileAllowed']
 
 class FileRequired(InputRequired):
     '''
         '''
         檢查 datalist 每個元素都應該是 cgi.FieldStorage 的 instance (多檔) 或是本身就是 cgi.FieldStorage
         '''
-        from cgi import FieldStorage
         if isinstance(data, list) and len(data) > 0:
             for each_data in data:
                 if not isinstance(each_data, FieldStorage):
         return False
 
     def __call__(self, form, field):
-        from wtforms.validators import StopValidation
         if not self._check_fieldstorage(field.data):
             if self.message is None:
                 message = field.gettext('This field is required for file(s).')
         self.message       = message
 
     def _check_allowed_types(self, data):
-        from cgi import FieldStorage
         pass_flag = True
         if isinstance(data, list):
             for each_data in data:
         return pass_flag
 
     def __call__(self, form, field):
-        from wtforms.validators import ValidationError
         if not self._check_allowed_types(field.data):
             raise ValidationError(self.message)