Пример #1
0
class UserChangeSerializer(rest.Serializer):
    old = rest.CharField(allow_null=False, allow_blank=False)
    new = rest.CharField(allow_null=False,
                         allow_blank=False,
                         max_length=12,
                         min_length=6)
    again = rest.CharField(allow_null=False,
                           allow_blank=False,
                           max_length=12,
                           min_length=6)
Пример #2
0
class RepositorySerializer(rest.ModelSerializer):
    author_name = rest.CharField(source='author.get_full_name', read_only=True)

    class Meta:
        model = RepositoryModel
        fields = ('id', 'title', 'content', 'update', 'author', 'author_name')
        read_only_fields = ('id', 'update')
Пример #3
0
class HandleProcessSerializerU(rest.Serializer):
    status = rest.ChoiceField(choices=('ok', 'no'))
    addreview = rest.CharField(allow_null=True, max_length=618)
    delhistory = rest.ListField()

    class Meta:
        fields = ('status', 'addreview', 'delhistory')
Пример #4
0
class PersonalSettingSerializer(rest.Serializer):
    full_name = rest.CharField(max_length=32, allow_null=False)
    email = rest.EmailField(max_length=62, allow_null=False)
    phone = rest.IntegerField(allow_null=False)
    jobnumber = rest.CharField(max_length=5, allow_null=False)
    workplace = rest.CharField(max_length=5, allow_null=False)

    def validate_phone(self, attrs):
        if not re.match(r'^1[34589]\d{9}$', str(attrs)):
            raise rest.ValidationError('手机号码不合法')
        return attrs

    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
Пример #5
0
class SubmitProcessSerializerL(rest.ModelSerializer):
    organizer = rest.CharField(source='organizer.get_full_name')
    content = rest.SerializerMethodField(read_only=True)
    at_leader = rest.SerializerMethodField(read_only=True)

    def get_at_leader(self, obj):
        result = ''
        for i in UserModel.objects.filter(
                id__in=re.findall(r'"(\d+)"', obj.at_leader)):
            result += (i.get_full_name() + '、')
        return result[:-1]

    def get_content(self, obj):
        result = list()
        for i, value in enumerate(json.loads(obj.content)):
            if user := UserModel.objects.filter(id__exact=value[0]).first():
                username = f'{user.get_full_name()} ({user.username})'
            else:
                username = '******'
            result.append([username, value[1], value[2], i])
        return result