def clean_message(self): message = self.cleaned_data['message'] if "quelq choses d'injures in message": forms.validationError( 'On ne veut pas entendre ce type de message ici') return message
def clean_age(self): age = self.cleaned_data.get('age') if age > 120: raise forms.validationError('you may be too old for this class') elif age < 10: raise forms.validationError('you may be young old for this class') return age
def clean_precio(self): precio = self.cleaned_data.get("precio") if precio <= 200.00: raise forms.validationError("El precio minimo es de $200.00") elif precio >= 19999.00: raise forms.validationError("El precio maximo es de $19999.00") else: return precio
def clean(self, *args, **kwargs): username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') if username and password: user = authenticate(username=username, password=password) if not user: raise forms.validationError("Cet utilisateur n'existe pas") if not user.check_password(password): raise forms.validationError('Mot de passe incorrect') if not user.is_active: raise forms.validationError('Cet utilisateur n est pas activé') return super(UserLoginForm, self).clean(*args, **kwargs)
def clean_tel(self): tel = self.cleaned_data.get("tel") if len(tel) == 0: raise forms.validationError("电话不能为空!!!!!") return tel
def clean(self): data = self.cleaned_data password = self.cleaned_data.get('password') password2 = self.cleaned_data.get('password') if password2 != password: raise forms.validationError("passwords must match.") return data
def clean_email(self): email = self.cleaned_data.get('email') email_qs = employers.objects.filter(email=email) if email_qs.exits(): raise forms.validationError( "this email has already been registered") return email
def clean_email(self, *args, **kwargs): email = self.cleaned_data.get('email') print(email) if email.endswith(".edu"): raise forms.validationError( "This is not a valid email. Please don't use .edu.") return email
def clean_username(self): username = self.cleaned_data.get('username') username_qs = User.objects.filter(username=username) if username_qs.exits(): raise forms.validationError( "this username has already been registered") return username
def clean(self, values): if self.valid_queryset is not None: qs = self.valid_queryset.filter(username__in=values) if len(qs) != len(values): raise forms.validationError(_('Not all users are part of the valid search space!')) return values
def clean_email(self): email = self.cleaned_data.get('email') email_base, email_provider = email.split('@') domain, extension = email.split('.') if not ".com" in email: raise forms.validationError("Please use a .com address") return email
def clean_password_two(self): password_one = self.cleaned_data['password_one'] password_two = self.cleaned_data['password_two'] if password_one ==password_two: pass else: raise forms.validationError('password no coinciden')
def clean_email(self): email = self.cleaned_data['email'] try: u = User.objects.get(email=email) except User.DoesNotExit: return email raise forms.validationError('Email ya registrado')
def add_vacation(request): if request.method == "POST": form = AddVacation(request.POST) if form.is_valid(): userObj = form.cleaned_data start_date = userObj['start_date'] end_date = userObj['end_date'] description = userObj['description'] username = request.session['username'] #user = MongoUser.objects.filter(username = username).get() id = len(Vacation.objects.filter( employee=username)) + 1 #number of vacations per user duration = np.busday_count(start_date, end_date) if (duration <= 0): raise forms.validationError( "the vacation is for less than one day") else: v = Vacation(idd=id, employee=username, start_date=str(start_date), end_date=str(end_date), description=description, total_period=duration) v.save() else: form = AddVacation() return render(request, 'vacation_added.html', {'form': form})
def clean_password2(self): if password1 in self.cleaned_data: password1 = self.cleaned_data['password1'] password2 = self.cleaned_data['password2'] if password1 == password2: return password2 raise forms.validationError('Password does not match')
def clean_email(self): email = self.cleaned_data['email'] try: email = User.objects.get(email=email) except User.DoesNotExist: return email raise forms.validationError('Correo Electronico ya Existe')
def clean(self): all_clean_data = super().clean() password = all_clean_data['password'] vpassword = all_clean_data['verify_password'] if password != vpassword: raise forms.validationError("Make Sure Password Matches!")
def clean_username(self): username = self.cleaned_data['username'] try: u = User.objects.get(username=username) except user.DoesNotExist: return username raise forms.validationError('Nombre de Usuario ya Registrado')
def clean_age(self): age = self.cleaned_data.get("age") if len(age) == 0: raise forms.validationError("年龄不能为空!!!!!!") return age
def clean_name(self): name = self.cleaned_data.get("name") if len(name) == 0: raise forms.validationError("用户名不能为空!!!!!") return name
def clean(self): all_clean_data = super().clean() email = all_clean_data['email'] vmail = all_clean - data['verify_email'] if email != vmail: raise forms.validationError("make sure email match")
def clean_username(self): username = self.cleaned_data['username'] try: u = User.objects.get(username=username) except User.DoesNotExit: return username raise forms.validationError('Nombre de usuario ua exixte')
def clean_password1(self): password1 = self.cleaned_data.get('password1') if len(password1) < 6: raise forms.ValidationError("密码太短!") elif len(password1) > 20: raise forms.validationError("密码太长!") return password1
def clan_password_2(self): #hace la validacion del password_2 password_1 = self.cleaned_data['password_1'] password_2 = self.cleaned_data['password_2'] if password_1 == password_2: pass else: raise forms.validationError('PAsswords no Coinciden')
def clean(self, *args,**kwargs): email = self.cleaned_data.get('email') email2 = self.cleaned_data.get('email2') print(email,email2) if email != email2: raise forms.validationError("Email must match") email_qs = User.objects.filter(email=email) if email_qs.exists();
def clean_url(self): url = self.cleaned_data['url'] valid_extensions = ['jpg', 'jpeg'] extension = url.rsplit('.', 1)[1].lower() if extension not in valid_extensions: raise forms.validationError( 'The given url doesn\'t match valid image extensions.') return url
def clean_password2(self): cd = self.cleaned_data if cd['password'] != cd['password2']: raise forms.validationError(u'Password Incorrect!') return cd['password2']
def clean_title(self, *args, **kwargs): instance = self.instance title = self.cleaned_data.get('title') qs = BlogPost.objects.filter(title__iexact=title) if instance is not None: qs = qs.exclude(pk=instance.pk) if qs.exists(): raise forms.validationError("This title has already been used. Please try again.") return title
def clean(self, *args, **kwargs): data = self.clean_data content = data.get('content', None) if content == "": content = None image = data.get('image', None) if content is None and image is None: raise forms.validationError('Content or image is required.') return super().clean(*args, **kwargs)
def clean(self): """ Adds validation to check that no two links have the same anchor or URL and that all links have both an anchor and URL. """ if any(self.errors): return anchors = [] urls = [] duplicates = False for form in self.forms: if form.cleaned_data['anchor'] url = form.cleaned_data['url'] # Check that no two links have the same anchor or URL if anchor and url: if anchor in anchors: duplicates = True anchors.append(anchor) if url in urls: duplicates = True urls.append(url) if duplicates: raise forms.validationError( 'Links must have unique anchors and URLs.', code='duplicate_links' ) # Check that all links have both an anchor and URL if url and not anchor: raise forms.validationError( 'All links must have an anchor.', code='missing_anchor' ) elif anchor and not url: raise forms.validationError( 'All links must have a URL.', code='missing_URL' )
def clean(self, *args, **kwargs): data = self.cleaned_data() about = data.get('about') print(about) if about == '': about = None photo = data.get('images') if about is None and ohoto is None: raise forms.validationError('about or photo must be there.') super().clean(*args, **kwargs)
def clean_username(self): username = self.cleaned_data.get('username') if len(username) < 6: raise forms.validationError("用户名必须至少为6个字符!") elif len(username) > 50: raise forms.ValidationError("用户名太长!") else: filter_result = User.objects.filter(username__exact=username) if len(filter_result) > 0: raise forms.ValidationError("用户名已存在!") return username
def clean(self, *args, **kwargs): username = self.cleaned_data.get("username") password = self.cleaned_data.get("password") if username and password: user = authenticate(username=username, password=password) if not user: raise forms.ValidationError("This user does not exit") if not user.check_password(password): raise forms.ValidationError("Incorrect password") if not user.is_active: raise forms.validationError("This user is not longer active") return super(UserLoginForm, self).clean(*args, **kwargs)
class UserLoginForm(froms.Form): #username = forms.CharField() password = forms.CharField(widget=forms.PasswordInput) def clean(self, *args, **kwargs): #username = self.cleaned_data.get("username") email = self.cleaned_data.get("email") password = self.cleaned_date.get("email") #user_qs = User.objects.filter(username=username) #if user_qs.count() == 1: # user = user_qs.first() if email and password: user = authenticate(email=email, password=password) if not user: raise forms.validationError("This user does not exist") if not user.check_password(password): raise forms.validationError("Incorrect password") if not user.is_active: raise forms.validationError("This user is not longer active.") return super(UserLoginForm,self).clean(*args, **kwargs)
def updateVacation(request): if request.is_ajax(): start_date = request.POST.get('start_date') end_date = (request.POST.get('end_date')) description = request.POST.get('description') duration = np.busday_count(start_date, end_date) if (np.busday_count(end_date, datetime.date.today()) <= 0): raise forms.validationError("you can't edit old vacations") if (duration <= 0): raise forms.validationError( "the vacation is for less than one day") else: idd = request.POST.get('idd') username = request.session['username'] user = User.objects.filter(username=username).get() vacation = Vacation.objects.filter(employee=user, idd=idd).update( start_date=start_date, end_date=end_date, description=description, total_period=duration) return HttpResponse("success")
def clean_message(self): message=self.cleaned_data.get('message','') num_words=len(message.split()) if (num_words < 4): raise forms.validationError("Not enough Words") return message
def clean_my_code(self): my_code = self.cleaned_data['my_code'] if my_code != 'guess': raise forms.validationError("code is error") # 邀请码不正确! return my_code