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
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
def validate_phone(self, attrs): if not re.match(r'^1[34589]\d{9}$', str(attrs)): raise rest.ValidationError('手机号码不合法') return attrs
def validate_password(self, attrs): if not re.match(r'^\S{6,16}$', attrs): raise rest.ValidationError('密码不合法') return make_password(attrs)
def validate_username(self, attrs): if not re.match(r'^[A-Za-z0-9-_.]+$', attrs): raise rest.ValidationError('用户名不合法') return attrs