Esempio n. 1
0
    def clean(self):
        cleaned_data = forms.ModelForm.clean(self)

        self.form_start = ExtendedDateForm(
            filter_fields(self.data, 'start_date-'))
        self.form_end = ExtendedDateForm(filter_fields(self.data, 'end_date-'))

        if not self.form_start.is_valid():
            self._errors['start_date'] = \
                self.form_start.get_error_messages()
        if not self.form_end.is_valid():
            self._errors['end_date'] = \
                self.form_end.get_error_messages()

        return cleaned_data
Esempio n. 2
0
    def clean(self):
        cleaned_data = forms.ModelForm.clean(self)

        self.form_established = ExtendedDateForm(
            filter_fields(self.data, 'established-'))
        self.form_defunct = ExtendedDateForm(
            filter_fields(self.data, 'defunct-'))

        if not self.form_established.is_valid():
            self._errors['established'] = \
                self.form_established.get_error_messages()
        if not self.form_defunct.is_valid():
            self._errors['defunct'] = \
                self.form_defunct.get_error_messages()

        return cleaned_data
Esempio n. 3
0
 def test_filter_fields(self):
     data = {
         'established-millenium1': '1',
         'established-century1': '2',
         'defunct-millenium1': '3',
         'defunct-century1': '3',
     }
     data = filter_fields(data, 'established-')
     self.assertEquals(data['millenium1'], '1')
     self.assertEquals(data['century1'], '2')
Esempio n. 4
0
    def clean(self):
        cleaned_data = forms.ModelForm.clean(self)

        self.form_start = ExtendedDateForm(
            filter_fields(self.data, 'inclusive-start-'))
        self.form_end = ExtendedDateForm(
            filter_fields(self.data, 'inclusive-end-'))

        if not self.form_start.is_valid():
            self._errors['inclusive-start'] = \
                self.form_start.get_error_messages()
        if not self.form_end.is_valid():
            self._errors['inclusive-end'] = \
                self.form_end.get_error_messages()

        if 'decoy' in cleaned_data and len(cleaned_data['decoy']) > 0:
            self._errors["decoy"] = self.error_class(
                ["Please leave this field blank"])

        return cleaned_data
Esempio n. 5
0
    def clean(self):
        cleaned_data = forms.ModelForm.clean(self)

        if (not cleaned_data.get('file')
                and not cleaned_data.get('source_url')):
            self.add_error('source_url', '')
            self.add_error('file', '')
            self.add_error(None,
                           'Please upload a file or specify a source url')

        self.form_date_taken = ExtendedDateForm(
            filter_fields(self.data, 'date-taken-'))

        if not self.form_date_taken.is_valid():
            self._errors['date_taken'] = \
                self.form_date_taken.get_error_messages()

        return cleaned_data