Exemplo n.º 1
0
class DescribeDepartmentMemberValidator(serializers.Serializer):
    department_id = serializers.CharField(max_length=20,
                                          required=False,
                                          validators=[department_validator],
                                          error_messages=error_message('部门id'))

    page_size = serializers.IntegerField(
        required=False,
        max_value=settings.MAX_PAGE_SIZE,
        min_value=10,
        default=10,
        error_messages=error_message('page_size'))

    page_num = serializers.IntegerField(
        required=False,
        max_value=settings.MAX_PAGE_NUM,
        min_value=0,
        default=1,
        error_messages=error_message('page_num'))

    def validate(self, data):
        department_id = data.get('department_id', None)
        if not department_id:
            department_id = PortalDepartment.objects.first().department_id
            data['department_id'] = department_id
        else:
            department_validator(department_id)
        return data
Exemplo n.º 2
0
class RenameDepartmentValidator(serializers.Serializer):
    department_id = serializers.CharField(max_length=20,
                                          required=True,
                                          validators=[department_validator],
                                          error_messages=error_message('部门id'))
    name = serializers.CharField(max_length=30,
                                 required=True,
                                 error_messages=error_message('部门名称'))
Exemplo n.º 3
0
class DescribeDepartmentMemberDetailValidator(serializers.Serializer):
    member_id = serializers.CharField(required=True,
                                      max_length=20,
                                      validators=[username_validator],
                                      error_messages=error_message('成员id'))

    member_type = serializers.ChoiceField(
        required=True,
        choices=['hankou', 'cloudin', 'tenant'],
        error_messages=error_message('成员类型'))
Exemplo n.º 4
0
class ChangeDepartmentValidator(serializers.Serializer):
    member_list = serializers.ListField(required=True,
                                        child=serializers.CharField(
                                            max_length=20,
                                            validators=[username_validator]),
                                        error_messages=error_message('成员ID列表'))
    department_id = serializers.CharField(
        max_length=20,
        required=True,
        validators=[department_validator],
        error_messages=error_message('所在部门id'))
Exemplo n.º 5
0
class CreateDepartmentValidator(serializers.Serializer):
    name = serializers.CharField(max_length=30,
                                 required=True,
                                 error_messages=error_message('部门名称'))
    description = serializers.CharField(max_length=200,
                                        required=False,
                                        default=gen_description,
                                        error_messages=error_message('部门描述'))
    parent_department_id = serializers.CharField(
        max_length=20,
        required=True,
        validators=[department_validator],
        error_messages=error_message('直接上级部门id'))
Exemplo n.º 6
0
class UpdateDepartmentMemberDetailValidator(serializers.Serializer):
    member_id = serializers.CharField(required=True,
                                      max_length=20,
                                      validators=[username_validator],
                                      error_messages=error_message('成员id'))

    member_type = serializers.ChoiceField(
        required=True,
        choices=['hankou', 'cloudin', 'tenant'],
        error_messages=error_message('成员类型'))

    main_name = serializers.CharField(max_length=30,
                                      required=False,
                                      error_messages=error_message('主联系人姓名'))

    main_phone = serializers.CharField(required=False,
                                       max_length=25,
                                       min_length=6,
                                       validators=[phone_unused_validator],
                                       error_messages=error_message('主联系人手机号'))

    backup_name = serializers.CharField(
        max_length=30, required=False, error_messages=error_message('备用联系人姓名'))

    backup_phone = serializers.CharField(
        required=False,
        max_length=25,
        min_length=6,
        validators=[phone_unused_validator],
        error_messages=error_message('备用联系人手机号'))

    company_name = serializers.CharField(max_length=100,
                                         required=False,
                                         error_messages=error_message('公司名称'))

    company_website = serializers.CharField(
        max_length=100, required=False, error_messages=error_message('公司网址'))

    company_addr = serializers.CharField(max_length=100,
                                         required=False,
                                         error_messages=error_message('公司地址'))

    def validate(self, data):
        update_info = dict(name=data.get('main_name'),
                           phone=data.get('main_phone'),
                           backup_name=data.get('backup_name'),
                           backup_phone=data.get('backup_phone'),
                           company_name=data.get('company_name'),
                           company_website=data.get('company_website'),
                           company_addr=data.get('company_addr'))
        update_info = {k: v for k, v in update_info.items() if v}
        data['update_info'] = update_info
        return data
Exemplo n.º 7
0
class CreateDepartmentMembersValidator(serializers.Serializer):
    department_id = serializers.CharField(
        max_length=20,
        required=True,
        validators=[department_validator],
        error_messages=error_message('所在部门id'))

    member_type = serializers.ChoiceField(
        required=True,
        choices=['hankou', 'cloudin', 'tenant'],
        error_messages=error_message('成员类型'))

    modify_init_password = serializers.BooleanField(
        required=False,
        default=True,
        error_messages=error_message('初次登录是否修改密码'))
Exemplo n.º 8
0
class SetZoneCurrentValidator(serializers.Serializer):
    zone = serializers.CharField(max_length=30,
                                 required=True,
                                 error_messages=error_message('部门名称'))
Exemplo n.º 9
0
class CreateHankouMemberValidator(serializers.Serializer):
    main_name = serializers.CharField(max_length=30,
                                      required=True,
                                      error_messages=error_message('主联系人姓名'))

    main_phone = serializers.CharField(required=True,
                                       max_length=25,
                                       min_length=6,
                                       validators=[phone_unused_validator],
                                       error_messages=error_message('主联系人手机号'))

    backup_name = serializers.CharField(
        max_length=30,
        required=False,
        default=None,
        error_messages=error_message('备用联系人姓名'))

    backup_phone = serializers.CharField(
        required=False,
        max_length=25,
        min_length=6,
        default=None,
        validators=[phone_unused_validator],
        error_messages=error_message('备用联系人手机号'))

    email = serializers.EmailField(required=True,
                                   max_length=60,
                                   validators=[email_unused_validator],
                                   error_messages=error_message('邮箱'))

    password = serializers.CharField(required=True,
                                     max_length=30,
                                     min_length=6,
                                     error_messages=error_message('用户密码'))

    company_name = serializers.CharField(max_length=100,
                                         required=False,
                                         error_messages=error_message('公司名称'))

    company_website = serializers.CharField(
        max_length=100, required=False, error_messages=error_message('公司网址'))

    company_addr = serializers.CharField(max_length=100,
                                         required=False,
                                         error_messages=error_message('公司地址'))

    def validate(self, data):

        if data.get('main_phone') == data.get('backup_phone'):
            raise serializers.ValidationError(u"主联系人手机号和备用联系人手机号不能是相同")

        if data.get('main_name') == data.get('backup_name'):
            raise serializers.ValidationError(u"主联系人和备用联系人不能是同一个人")

        data['member_info'] = dict(
            name=data.get('main_name'),
            phone=data.get('main_phone'),  # see AccountService.create
            backup_name=data.get('backup_name'),
            backup_phone=data.get('backup_phone'),  # see AccountService.create
            account_type=AccountType.HANKOU,  # see AccountService.create
            status=data.get('status', 'enable'),
            area=data.get('area'),
            email=data.get('email'),
            password=data.get('password'),
            company_name=data.get('company_name'),
            company_website=data.get('company_website'),
            company_addr=data.get('company_addr'),
        )
        return data
Exemplo n.º 10
0
class DescribeDepartmentValidator(serializers.Serializer):
    department_id = serializers.CharField(max_length=20,
                                          default='',
                                          validators=[department_validator],
                                          error_messages=error_message('部门id'))
Exemplo n.º 11
0
class RemoveDepartmentMemberValidator(serializers.Serializer):
    member_list = serializers.ListField(required=True,
                                        child=serializers.CharField(
                                            max_length=20,
                                            validators=[username_validator]),
                                        error_messages=error_message('成员ID列表'))