def full_clean(self): self._errors = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = [] for form in self.forms: self._errors.update(form.errors) if hasattr(form, 'cleaned_data'): self.cleaned_data.append(form.cleaned_data) if self._errors: delattr(self, 'cleaned_data')
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 self.empty_permitted and not self.has_changed(): self.cleaned_data = None return for name, field in self.fields.items(): self.clean_field(name, field) try: self.cleaned_data = self.clean() except ValidationError, e: self._errors[NON_FIELD_ERRORS] = e.messages
class UnionFilterForm(Form): ''' Form that contains more Filter Forms, data for this form is list of data for its Filter Forms. ''' def __init__(self, data=None, data_cleaned=False, initial=None, layout_class=UnionFilterFormLayout, form_class=None, *content, **kwd): """ Form containting CompoundFilterForms (class FilterForms), between them is logical OR. Can be initilalized using data parametr data - normal form data, or if data_cleaned=True, then data parametr is considered to be cleaned_data (used when loaded from corba backend). """ if not form_class: raise RuntimeError( "You have to specify form_class for UnionFilterForm!") if data: if not data_cleaned and data.has_key('json_data'): data = simplejson.loads(data['json_data']) else: debug('data aren\'t json') self.form_class = form_class self.forms = [] self.data_cleaned = data_cleaned super(UnionFilterForm, self).__init__(data, initial=initial, layout_class=layout_class, *content, **kwd) self.set_tattr(action=kwd.get('action') or self.get_default_url()) self.media_files = [ '/js/filtertable.js', '/js/scw.js', '/js/interval_fields.js', '/js/scwLanguages.js', '/js/form_content.js', '/service_actions.js', '/filter_forms_javascript.js', '/js/check_filter_forms_javascript.js', ] # Submit on enter. self.onkeypress = 'if (event.keyCode == 13) {sendUnionForm(this);}' def set_fields_values(self): if not self.is_bound: # if not bound, then create one empty dictionary self.forms.append(self.form_class()) else: # else create form for each value in 'data' list for form_data in self.data: debug('Creating form in unionu with data: %s' % form_data) debug('a that data are data_cleaned=%s' % self.data_cleaned) form = self.form_class(form_data, data_cleaned=self.data_cleaned) self.forms.append(form) def is_empty(self, exceptions=None): for form in self.forms: if form.is_empty(exceptions): return False return True def full_clean(self): self._errors = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = [] for form in self.forms: self._errors.update(form.errors) if hasattr(form, 'cleaned_data'): self.cleaned_data.append(form.cleaned_data) if self._errors: delattr(self, 'cleaned_data') def get_default_url(self): ''' Returns url for snadard path /OBJECTs/filter where OBJECT taken from self.form_class name OBJECTsFilterForm. If class name is not in format, than returns ''. ''' class_name = self.form_class.__name__ if class_name.endswith('FilterForm'): return '%sfilter/' % f_urls[class_name[:-10].lower()] else: return ''
class UnionFilterForm(Form): ''' Form that contains more Filter Forms, data for this form is list of data for its Filter Forms. ''' def __init__(self, data=None, data_cleaned=False, initial=None, layout_class=UnionFilterFormLayout, form_class=None, *content, **kwd): """ Form containting CompoundFilterForms (class FilterForms), between them is logical OR. Can be initilalized using data parametr data - normal form data, or if data_cleaned=True, then data parametr is considered to be cleaned_data (used when loaded from corba backend). """ if not form_class: raise RuntimeError( "You have to specify form_class for UnionFilterForm!") if data: if not data_cleaned and data.has_key('json_data'): data = simplejson.loads(data['json_data']) else: debug('data aren\'t json') self.form_class = form_class self.forms = [] self.data_cleaned = data_cleaned super(UnionFilterForm, self).__init__( data, initial=initial, layout_class=layout_class, *content, **kwd) self.set_tattr(action = kwd.get('action') or self.get_default_url()) self.media_files = ['/js/filtertable.js', '/js/scw.js', '/js/interval_fields.js', '/js/scwLanguages.js', '/js/form_content.js', '/service_actions.js', '/filter_forms_javascript.js', '/js/check_filter_forms_javascript.js', ] # Submit on enter. self.onkeypress = 'if (event.keyCode == 13) {sendUnionForm(this);}' def set_fields_values(self): if not self.is_bound: # if not bound, then create one empty dictionary self.forms.append(self.form_class()) else: # else create form for each value in 'data' list for form_data in self.data: debug('Creating form in unionu with data: %s' % form_data) debug('a that data are data_cleaned=%s' % self.data_cleaned) form = self.form_class( form_data, data_cleaned=self.data_cleaned) self.forms.append(form) def is_empty(self, exceptions=None): for form in self.forms: if form.is_empty(exceptions): return False return True def full_clean(self): self._errors = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = [] for form in self.forms: self._errors.update(form.errors) if hasattr(form, 'cleaned_data'): self.cleaned_data.append(form.cleaned_data) if self._errors: delattr(self, 'cleaned_data') def get_default_url(self): ''' Returns url for snadard path /OBJECTs/filter where OBJECT taken from self.form_class name OBJECTsFilterForm. If class name is not in format, than returns ''. ''' class_name = self.form_class.__name__ if class_name.endswith('FilterForm'): return '%sfilter/' % f_urls[class_name[:-10].lower()] else: return ''