def clean_text(self): data = self.cleaned_data['text'] if data == '': raise forms.ValidationError("Поле обязательно для заполнения") return data
def clean_phone_number(self): phone_number = self.cleaned_data.get('phone_number', '').replace(' ', '') if not self.phone_number_regex.match(phone_number): raise forms.ValidationError(_('Please enter an UK phone number')) return phone_number
def clean_password2(self): password1 = self.cleaned_data.get("password1") password2 = super(UserCreationForm, self).clean_password2() if bool(password1) ^ bool(password2): raise forms.ValidationError("Fill out both fields") return password2
def clean(self): cleaned_data = super(ContactUserIncludingPasswordForm, self).clean() if Contact.objects.filter(username=cleaned_data.get("email")).exists(): raise forms.ValidationError( _('An user with the given email already exists')) return cleaned_data
def clean_field_name(self): data = self.cleaned_data['Productid'] if not data: # 如果data不满足满足条件 raise forms.ValidationError('data is invalid') return data
def clean_country(self): code = self.cleaned_data['country'] if code and (len(code) != 3 or not code.isalpha()): raise forms.ValidationError( u'Must be three characters (ISO 3166-1): e.g. USA, CAN, MNG') return code.upper()
def clean_description(self): description = self.cleaned_data.get("description") if not description: raise forms.ValidationError( _("This field is required")) return description
def check_login_to_unique(self, cleaned_data): login = cleaned_data.get('login') check_fist_2_letter_for_login = User.objects.filter(username__startswith=login[:2]) if check_fist_2_letter_for_login: mess = u'Логин не подходит уникальность по сокращениям (не уникальны первые 2 сивола логин)' raise forms.ValidationError(mess)
def check_email_to_unique(self, cleaned_data): email = cleaned_data.get('email') check_email_unique = User.objects.filter(email__iexact=email) if check_email_unique: mess = u'Такой email уже зарегистрирован' raise forms.ValidationError(mess)
def clean_name(self): name = self.cleaned_data.get('name') if len(name) == 1: raise forms.ValidationError('Please enter a valid name') return name
def check_passwords(self, cleaned_data): password1 = cleaned_data.get('password1') password2 = cleaned_data.get('password2') if password1 != password2: mess = u'Пароли не совпадают' raise forms.ValidationError(mess)
def clean_password2(self): cd = self.cleaned_data if cd['password'] != cd['password2']: raise forms.ValidationError('Passwords don\'t match.') return cd['password2']
def AnoValidator(ano): if ano < 0 and ano > date.today().year: raise forms.ValidationError('Data indisponivel') else: return ano
def clean_username(self, username, shallow=False): if not self.username_regex.match(username): raise forms.ValidationError( self.error_messages['invalid_username']) return username
def clean_hours_of_operation(self): hours_of_operation = self.cleaned_data.get("hours_of_operation") if not hours_of_operation: raise forms.ValidationError(_("This field is required")) return hours_of_operation
def valide_date(date): if date < datetime.date.today(): raise forms.ValidationError("The date cannot be in the past!") return date
def clean_music(self): music = self.cleaned_data.get("music") if not music: raise forms.ValidationError(_("This music is required")) return music
def clean_date(self): date = self.cleaned_data['date'] if date < datetime.date.today(): raise forms.ValidationError("Sorry, Invalid Date!") return date
def clean_time(self): time = self.cleaned_data.get("time") if not time: raise forms.ValidationError( _("This field is required")) return time
def clean_qq(self): cleaned_data = self.clean_data['qq'] if not cleaned_data.isdigit(): raise forms.ValidationError('必须是数字!') return int(cleaned_data)
def clean_image(self): image = self.cleaned_data.get("image") if not image: raise forms.ValidationError( _("This field is required")) return image
def validate_f_word(content): if "f**k" in content.lower(): raise forms.ValidationError("Can't tweet F word!") return content
def clean(self): if self.cleaned_data['price'] < 50: raise forms.ValidationError( message='Цена смартфона должна быть больше 50')
def clean(self): print(self.cleaned_data) if Category.objects.filter(name=self.cleaned_data.get("name")): raise forms.ValidationError(message="Category already exists") if len(self.cleaned_data.get("name")) is 0: raise forms.ValidationError(message="field is empty")
def clean_date(self): date = self.cleaned_data['appointment_date'] if date < datetime.date.today(): raise forms.ValidationError("The date cannot be in the past!") return date
def clean_address(self): address = self.cleaned_data.get("address") if not address: raise forms.ValidationError(_("This field is required")) return address
def __call__(self, value): if value.size > self.max_size: raise forms.ValidationError( _('Maximum allowed size is %(max_size)s') % {'max_size': filesizeformat(self.max_size)})
def clean_area(self): area = self.cleaned_data.get("area") if not area: raise forms.ValidationError(_("This field is required")) return area
def clean_age(self): data = self.cleaned_data['age'] if data < 18: raise forms.ValidationError("Вы слишком молоды!") return data
def clean_age(self): data = self.cleaned_data['age'] if data < 18: raise forms.ValidationError( "Лицам моложе 18-ти лет запрещено регистрироваться на сайте!") return data