예제 #1
0
 def full_clean(self):
     """
     Cleans all of self.data and populates self._errors and
     self.cleaned_data.
     """
     self._errors = ErrorDict()
     if not self.is_bound:  # Stop further processing.
         return
     self.cleaned_data = {}
     # If the form is permitted to be empty, and none of the form data has
     # changed from the initial data, short circuit any validation.
     if self.empty_permitted and not self.has_changed():
         return
     for name, field in self.fields.items():
         # value_from_datadict() gets the data from the data dictionaries.
         # Each widget type knows how to retrieve its own data, because some
         # widgets split data over several HTML fields.
         value = field.widget.value_from_datadict(self.data, self.files,
                                                  self.add_prefix(name))
         try:
             if isinstance(field, FileField):
                 initial = self.initial.get(name, field.initial)
                 value = field.clean(value, initial)
             else:
                 value = field.clean(value)
             self.cleaned_data[name] = value
             if hasattr(self, 'clean_%s' % name):
                 value = getattr(self, 'clean_%s' % name)()
                 self.cleaned_data[name] = value
         except ValidationError, e:
             self._errors[name] = e.messages
             if name in self.cleaned_data:
                 del self.cleaned_data[name]
예제 #2
0
 def full_clean(self):
     """
     Cleans all of self.data and populates self._errors and
     self.cleaned_data.
     """
     self._errors = ErrorDict()
     if not self.is_bound:  # Stop further processing.
         return
     self.cleaned_data = {}
     for name, field in self.fields.items():
         # value_from_datadict() gets the data from the dictionary.
         # Each widget type knows how to retrieve its own data, because some
         # widgets split data over several HTML fields.
         value = field.widget.value_from_datadict(self.data,
                                                  self.add_prefix(name))
         try:
             value = field.clean(value)
             self.cleaned_data[name] = value
             if hasattr(self, 'clean_%s' % name):
                 value = getattr(self, 'clean_%s' % name)()
                 self.cleaned_data[name] = value
         except ValidationError, e:
             self._errors[name] = e.messages
             if name in self.cleaned_data:
                 del self.cleaned_data[name]
예제 #3
0
 def full_clean(self):
     """
     Cleans all of self.data and populates self._errors and
     self.cleaned_data.
     """
     self._errors = ErrorDict()
     if not self.is_bound:  # Stop further processing.
         return
     self.cleaned_data = {}
     # If the form is permitted to be empty, and none of the form data has
     # changed from the initial data, short circuit any validation.
     if self.empty_permitted and not self.has_changed():
         return
     self._clean_fields()
     self._clean_form()
     if self._errors:
         delattr(self, 'cleaned_data')
예제 #4
0
파일: forms.py 프로젝트: rucky2013/MoleSys
 def full_clean(self):  #form接口 clean总入口
     """
     Cleans all of self.data and populates self._errors and
     self.cleaned_data.
     """
     self._errors = ErrorDict()
     if not self.is_bound:  # Stop further processing.必须是已绑定的表单
         return
     self.cleaned_data = {
     }  #.is_valid()输出True的时候f.cleaned_data才会有正确的数值..否则报错    一方面进行数据的校验,另一方面转为与form中字段对应的数据类型。而clearned_data就是保存转换后的结果
     # If the form is permitted to be empty, and none of the form data has
     # changed from the initial data, short circuit any validation.
     if self.empty_permitted and not self.has_changed():  # 如果允许为空而且数据没有改动
         return
     self._clean_fields()
     self._clean_form()
     self._post_clean()
     if self._errors:  # 每返回一次errors则清空一下cleaned_data(符合条件的数据)
         delattr(self, 'cleaned_data')