コード例 #1
0
 def clean_alt_email(self):
     email = self.cleaned_data['alt_email']
     if email != None and email != '':
         result = profile.Founder.objects.filter(alt_email=email)
         if result.count() > 1 or (result.count() == 1 and result[0].id != self.instance.id):
             raise ValidationError(message='Alt email already used')
     return email
コード例 #2
0
 def clean_username(self):
     username = self.cleaned_data['username']
     res = UserModel().objects.all().filter(username=username)
     if len(res) != 0:
         raise ValidationError(
             self.fields['username'].error_messages['username_taken'])
     return username
コード例 #3
0
 def clean(self, values):
     super(ReCaptcha2Field, self).validate(values[0])
     ret = validate_captcha(values[0], self.private_key)
     if not ret.is_clean:
         raise ValidationError(get_error_message(ret.error_code),
                               code=ret.error_code)
     return values[0]
コード例 #4
0
 def clean_password_2(self):
     pwd_1 = self.cleaned_data['password']
     pwd_2 = self.cleaned_data['password_2']
     if pwd_1 != pwd_2:
         raise ValidationError(
             self.fields['password_2'].error_messages['pwd_mismatch'])
     return pwd_1
コード例 #5
0
ファイル: admin.py プロジェクト: s-m-b/testbilling
 def clean(self):
     data = super().clean()
     _type = data.get('meta_type')
     code = data.get('meta_code')
     url = data.get('meta_url')
     amount = data.get('meta_amount')
     if _type == 'cash':
         if code or url or not amount:
             raise ValidationError('For cash payment specify amount only')
         data['metadata'] = {'type': _type, 'amount': float(amount.amount)}
         return data
     if _type == 'card':
         if amount or (not code and not url):
             raise ValidationError(
                 'For card payment use "code" and "url" fields')
         data['metadata'] = {'type': _type, 'code': code, 'url': url}
         return data
     raise ValidationError('Unknown payment type')
コード例 #6
0
ファイル: issues.py プロジェクト: renlei-great/SaaS2
    def clean_count(self):
        count = self.cleaned_data.get('count', '')
        if not count:
            count = int(self.request.tracer.price_policy.pro_member) - 1

        if int(count) > int(self.request.tracer.price_policy.pro_member) - 1:
            raise ValidationError(f'项目最多可以邀请{int(self.request.tracer.price_policy.pro_member) - 1} 人,请升级套餐')

        return count
コード例 #7
0
 def clean_email(self):
     valid_email = False
     email = self.cleaned_data['email']
     for edu in ActiveEdu.objects.all():
         if email.endswith(edu.domain):
             valid_email = True
     if not valid_email:
         raise ValidationError(
             self.fields['email'].error_messages['invalid_edu'])
     return email
コード例 #8
0
 def validate(self, value):
     # The first value is the captcha's key
     # The second value is the user's input
     #
     # The user input is encoded against the field's salt to validate.
     # Also, the field must exist in user's session, so the user can never
     #   use a replay attack against the captcha.
     encoded = encode_solution(self._salt, value[1])
     if value[0] != encoded or CURRENT.request.session.get(BASE_SESSION_KEY + self._salt) != encoded:
         raise ValidationError(_('Security code was not entered properly, or has expired.'))
コード例 #9
0
    def clean(self, value):
        assert self._content_type
        cells = []

        if value in EMPTY_VALUES:
            if self.required:
                raise ValidationError(self.error_messages['required'], code='required')
        else:
            model = self._content_type.model_class()
            get_builder = self._builders.get

            for elt in value.split(','):
                builder = get_builder(elt)

                if not builder:
                    raise ValidationError(self.error_messages['invalid'], code='invalid')

                cells.append(builder(self, model, elt))

        return cells
コード例 #10
0
    def to_python(self, value):
        """
        Validates that the input can be converted to a datetime. Returns a
        Python datetime.datetime object.
        """
        if not value:
            return []

        try:
            return json.loads(value)
        except ValueError, e:
            raise ValidationError(str(e))
コード例 #11
0
    def clean(self):
        cdata = self.cleaned_data

        if not self._errors:
            is_private = cdata.get('is_private', False)

            if is_private:
                owner = cdata.get('user')

                if not owner:
                    self.add_error(
                        'user',
                        ValidationError(
                            self.error_messages['orphan_private'],
                            code='orphan_private',
                        ))
                else:
                    req_user = self.user

                    if not req_user.is_staff:
                        if owner.is_team:
                            if req_user.id not in owner.teammates:
                                self.add_error(
                                    'user',
                                    ValidationError(
                                        self.error_messages['foreign_private'],
                                        code='foreign_private',
                                    ))
                        elif owner != req_user:
                            self.add_error(
                                'user',
                                ValidationError(
                                    self.error_messages['foreign_private'],
                                    code='foreign_private',
                                ))

            self.instance.cells = cdata['cells']

        return cdata
コード例 #12
0
    def clean(self, data, initial=None):
        f = super(VideoField, self).clean(data, initial)

        if f is None:
            return None
        elif not data and initial:
            return initial

        file = None
        buffer = None

        try:
            if hasattr(data, 'temporary_file_path'):
                file = data.temporary_file_path()
            else:
                if hasattr(data, 'read'):
                    buffer = data.read(HEADER)
                else:
                    buffer = data['content']

            if file:
                if not is_video(file):
                    raise ValidationError("1")
            elif buffer:
                if not is_video_buffer(buffer):
                    raise ValidationError("2")
            else:
                raise Exception(
                    "Can't get uploaded file's contents in usual way. Weird :("
                )
        except ValidationError:
            raise ValidationError(self.error_messages['invalid_video'])

        if hasattr(f, 'seek') and callable(f.seek):
            f.seek(0)
        return f
コード例 #13
0
 def clean_members_requested(self):
     members = int(self.cleaned_data['members_requested'])
     if members <= 0:
         raise ValidationError(self.fields['members_requested'].
                               error_messages['invalid_members'])
     return self.cleaned_data['members_requested']