コード例 #1
0
 def validate(self, attrs):
     file = get_workplace(True)
     if workplace := attrs.get('workplace'):
         if not file.get(workplace):
             raise rest.ValidationError('职场编号不合法')
         if jobnumber := attrs.get('jobnumber'):
             jobnumber = jobnumber[len(workplace):]
             if not file.get(workplace)['children'].get(jobnumber):
                 raise rest.ValidationError('工位编号不合法')
             attrs['jobnumber'] = jobnumber
コード例 #2
0
 def validate_at_leader(self, val):
     at_leader = list(set(str(val).split(',')))
     try:
         if UserModel.objects.filter(
                 id__in=at_leader).count() != len(at_leader):
             raise rest.ValidationError(detail='审核列表包含未识别的数据')
     except (Exception, ):
         raise rest.ValidationError(detail='审核列表包含未识别的数据')
     resval = ''
     for i in at_leader:
         resval += f'"{i}"'
     return resval
コード例 #3
0
 def validate_phone(self, attrs):
     if not re.match(r'^1[34589]\d{9}$', str(attrs)):
         raise rest.ValidationError('手机号码不合法')
     return attrs
コード例 #4
0
ファイル: user.py プロジェクト: paulzhousz/M-OAS
 def validate_password(self, attrs):
     if not re.match(r'^\S{6,16}$', attrs):
         raise rest.ValidationError('密码不合法')
     return make_password(attrs)
コード例 #5
0
ファイル: user.py プロジェクト: paulzhousz/M-OAS
 def validate_username(self, attrs):
     if not re.match(r'^[A-Za-z0-9-_.]+$', attrs):
         raise rest.ValidationError('用户名不合法')
     return attrs