1. William Wu
  2. pyramid_wtf

Commits

William Wu  committed 0a72b73

Improve code comments

  • Participants
  • Parent commits 677b600
  • Branches default

Comments (0)

Files changed (3)

File pyramid_wtf/fields.py

View file
  • Ignore whitespace
 
 class FileField(_FileField):
     '''
-    自訂配合 pyramid 使用的 FileField 類別,可接受一或多個檔案上傳
+    Used for handling single file field.
     '''
-
     def process_formdata(self, valuelist):
-        '檢查應該只有一個檔案'
         if len(valuelist) != 1:
             raise ValueError(self.gettext('Only one file is accepted.'))
         self.data = valuelist[0]
 
 class MultiFilesField(_FileField):
     '''
-    自訂配合 pyramid 使用的 FileField 類別,可接受多個檔案上傳
+    Used for handling multi files field.
     '''
     widget = _widgets.MultiFilesInput()
 

File pyramid_wtf/forms.py

View file
  • Ignore whitespace
 from wtforms.ext.csrf import SecureForm as _SecureForm
 
 class SecureForm(_SecureForm):
-
+    '''
+    This class uses pyramid builtin csrf facility.
+    '''
     def generate_csrf_token(self, csrf_context):
         return csrf_context.get_csrf_token()

File pyramid_wtf/validators.py

View file
  • Ignore whitespace
 
 class FileRequired(InputRequired):
     '''
-    檢查是否有選擇檔案上傳
+    Check if the field is valid file entity. This class could be used for single file / multi files field.
     '''
 
     def _check_fieldstorage(self, data):
         '''
-        檢查 datalist 每個元素都應該是 cgi.FieldStorage 的 instance (多檔) 或是本身就是 cgi.FieldStorage
+        :param data: Could be instance of cgi.FieldStorage, or a list which contains instances of cgi.FieldStorage.
         '''
         if isinstance(data, list) and len(data) > 0:
             for each_data in data:
 
 class FileAllowed:
     '''
-    檢查是否上傳符合要求的檔案類型
+    Check if the uploaded file(s) are valid mimetype(s).
     '''
 
     def __init__(self, allowed_types, message=None):
         self.message       = message
 
     def _check_allowed_types(self, data):
+        '''
+        :param data: Could be instance of cgi.FieldStorage, or a list which contains instances of cgi.FieldStorage.
+        '''
         pass_flag = True
         if isinstance(data, list):
             for each_data in data: