Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
	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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
    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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
 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
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
	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')
Ejemplo n.º 14
0
	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')		
Ejemplo n.º 15
0
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})
Ejemplo n.º 16
0
 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')
Ejemplo n.º 17
0
 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')
Ejemplo n.º 18
0
    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!")
Ejemplo n.º 19
0
 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')
Ejemplo n.º 20
0
    def clean_age(self):
        age = self.cleaned_data.get("age")

        if len(age) == 0:
            raise forms.validationError("年龄不能为空!!!!!!")

        return age
Ejemplo n.º 21
0
    def clean_name(self):
        name = self.cleaned_data.get("name")

        if len(name) == 0:
            raise forms.validationError("用户名不能为空!!!!!")

        return name
Ejemplo n.º 22
0
    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")
Ejemplo n.º 23
0
	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')	
Ejemplo n.º 24
0
 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
Ejemplo n.º 25
0
    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')
Ejemplo n.º 26
0
    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();
Ejemplo n.º 27
0
 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
Ejemplo n.º 28
0
    def clean_password2(self):

        cd = self.cleaned_data

        if cd['password'] != cd['password2']:

            raise forms.validationError(u'Password Incorrect!')

        return cd['password2']
Ejemplo n.º 29
0
 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
Ejemplo n.º 30
0
 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)
Ejemplo n.º 31
0
    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'
                )
Ejemplo n.º 32
0
    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)
Ejemplo n.º 33
0
    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
Ejemplo n.º 34
0
 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)
Ejemplo n.º 35
0
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")
Ejemplo n.º 37
0
	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
Ejemplo n.º 38
0
 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