Esempio n. 1
0
    def create_stu_adm(self, request, *args, **kwargs):
        check_token = pd_super_adm_token(request)
        if check_token:
            return check_token

        # 用户名
        user_name = request.data.get('user_name')
        # 手机号
        phone_number = request.data.get("phone_number")
        # 密码
        password = request.data.get("password")
        # 真实姓名
        name = request.data.get('name')
        # 真实姓名
        school_id = request.data.get('school_id')

        if check_user_name(user_name):
            message = "用户名已存在"
            return response_success_200(code=STATUS_USER_NAME_DUPLICATE,
                                        message=message)
        if check_phone_number(phone_number):
            message = "该手机号已被注册"
            return response_success_200(code=STATUS_PHONE_NUMBER_DUPLICATE,
                                        message=message)
        if not pd_phone_number(phone_number):
            message = "手机号格式错误"
            return response_success_200(code=STATUS_PHONE_NUMBER_DUPLICATE,
                                        message=message)

        # 创建用户详情 并获得他的id
        user_details_id = UserDetails.objects.create(name=name).id

        # 加密
        # request.data["password"] = my_encode(password)
        # request.data['user_details'] = user_details_id
        # request.data['role'] = -2
        # request.data['token'] = "-1"

        # serializer = self.get_serializer(data=request.data)
        # serializer.is_valid(raise_exception=True)
        # self.perform_create(serializer)
        # headers = self.get_success_headers(serializer.data)
        # return response_success_200(code=STATUS_200_SUCCESS, data=serializer.data, headers=headers)

        # 创建user
        user_id = User.objects.create(user_name=user_name,
                                      password=my_encode(password),
                                      phone_number=phone_number,
                                      role=-2,
                                      user_details_id=user_details_id,
                                      token=-1).id
        Schooladm.objects.create(
            school_id=school_id,
            user_id=user_id,
        )

        return response_success_200(message="成功!!!!")
Esempio n. 2
0
def adm_update_user_details(user_update: User, request):
    phone_number = request.data.get("phone_number")
    if phone_number and phone_number != user_update.phone_number:
        if not pd_phone_number(phone_number):
            return response_error_400(message="手机号输入有误")
        if User.objects.exclude(pk=user_update.id).filter(
                phone_number=phone_number):
            return response_error_400(message="手机号已存在")
        user_update.phone_number = phone_number

    # 获得传过来的参数
    user_details = request.data.get('user_details')
    print(user_details)
    # 获得需要修改的userDetails
    user_detail_update = user_update.user_details
    sex = user_details.get('sex')
    name = user_details.get('name')
    birthday = user_details.get('birthday')
    card = user_details.get('card')
    qq = user_details.get('qq')
    email = user_details.get('email')

    if sex and sex is not user_detail_update.sex:
        user_detail_update.sex = sex
    if name and name is not user_detail_update.name:
        user_detail_update.name = name
    if birthday and birthday != user_detail_update.birthday:
        check_time = check_time_stamp(int(birthday))
        print(check_time)
        if check_time:
            return response_error_400(message=check_time)
        user_detail_update.birthday = birthday
    if card and card != user_detail_update.card:
        if not pd_card(card):
            return response_error_400(message="身份证输入有误")
        if UserDetails.objects.exclude(pk=user_detail_update.id).filter(
                card=card):
            return response_error_400(message="身份证已存在")
        user_detail_update.card = card
    if qq and qq != user_detail_update.qq:
        if not pd_qq(qq):
            return response_error_400(message="qq输入有误")
        if UserDetails.objects.exclude(pk=user_detail_update.id).filter(qq=qq):
            return response_error_400(message="qq已存在")
        user_detail_update.qq = qq
    if email and email != user_detail_update.email:
        if not pd_email(email):
            return response_error_400(message="email输入有误")
        if UserDetails.objects.exclude(pk=user_detail_update.id).filter(
                email=email):
            return response_error_400(message="email已存在")
        user_detail_update.email = email

    # 保存修改
    user_update.save()
    user_detail_update.save()
Esempio n. 3
0
def batch_import_test(file):
    excel_data = pd.read_excel(file, header=0, dtype='str')
    test = []
    i = 1
    card_list = []
    phone_list = []

    for dt in excel_data.iterrows():
        i = i + 1
        message = ""

        card = dt[1]['身份证']
        phone_number = dt[1]['手机号码']
        qq = dt[1]['QQ(选填)']
        email = dt[1]['邮箱(选填)']

        if not dt[1]['家长姓名'] or not card or not phone_number:
            message += "有空字段"

        # 判断身份证的格式是否存在
        if not pd_card(card):
            message += ",身份证格式错误"
        elif card in card_list:
            message += f",身份证和{card_list.index(card) + 1}重复"
        elif User.objects.filter(user_name=card):
            message += ",身份证已经注册存在"

        if not pd_phone_number(phone_number):
            message += ",手机号格式错误"
        elif phone_number in phone_list:
            message += f",手机号和{phone_list.index(phone_number) + 1}重复"
        elif User.objects.filter(phone_number=phone_number):
            message += ",手机号码已经注册存在"

        #  验证qq号
        if not qq and not pd_qq(qq):
            message += ",qq号格式错误"

        # 验证邮箱
        if not email and not pd_email(email):
            message += ",邮箱格式错误"

        if message:
            test.append({"index": i, "message": message})
        card_list.append(card)
    if phone_number:
        phone_list.append(phone_number)

    if len(test) > 0:
        return response_error_400(code=STATUS_PARAMETER_ERROR,
                                  message="有错误信息",
                                  err_data=test,
                                  length=len(test))
    return None
def batch_import_test(file):
    excel_data = pd.read_excel(file, header=0, dtype='str')
    test = []
    i = 1
    card_list = []
    phone_list = []
    for dt in excel_data.iterrows():
        i = i + 1
        message = ""
        # 添加用户信息
        card = dt[1]['身份证']
        phone_number = dt[1]['手机号码(选填)']
        school = dt[1]['学校名称']
        class_name = dt[1]['班级']

        if not dt[1]['学生姓名'] or not card or not class_name or not school:
            message += "有空字段"

        # 判断身份证的格式是否存在
        if not pd_card(card):
            message += ",身份证格式错误"
        elif card in card_list:
            message += f",身份证和{card_list.index(card) + 1}重复"
        elif UserDetails.objects.filter(card=card):
            message += ",身份证已经注册存在"

        if phone_number:
            if not pd_phone_number(phone_number):
                message += ",手机号格式错误"
            elif phone_number in phone_list:
                message += f",手机号和{phone_list.index(phone_number) + 1}重复"
            elif User.objects.filter(phone_number=phone_number):
                message += ",手机号码已经注册存在"

        if not School.objects.filter(school_name=school):
            message += ",学校不存在"
        elif not Class.objects.filter(
                class_name=class_name,
                school_id=School.objects.get(school_name=school).id):
            message += ",学校中班级名不存在"

        if message:
            test.append({"index": i, "message": message})
        card_list.append(card)
    if phone_number:
        phone_list.append(phone_number)

    if len(test) > 0:
        return response_error_400(code=STATUS_PARAMETER_ERROR,
                                  message="有错误信息",
                                  err_data=test,
                                  length=len(test))
    return None
Esempio n. 5
0
def check_student_insert_info(request):
    school = request.data.get('school')
    clazz = request.data.get('clazz')
    card = request.data.get('card')
    phone_number = request.data.get('phone_number')
    name = request.data.get('name')
    qq = request.data.get('qq')
    email = request.data.get('email')

    # 不能为空的数据
    if not card:
        return response_success_200(code=STATUS_PARAMETER_ERROR,
                                    message="card 不能为空")
    if not name:
        return response_success_200(code=STATUS_PARAMETER_ERROR,
                                    message="name 不能为空")

    # 学校关联
    if not School.objects.filter(id=school):
        return response_success_200(code=STATUS_PARAMETER_ERROR,
                                    message="学校不存在")
    # 班级关联
    if not Class.objects.filter(id=clazz):
        return response_success_200(code=STATUS_PARAMETER_ERROR,
                                    message="班级不存在")
    # 用户检查是否存在
    if UserDetails.objects.filter(card=card):
        return response_success_200(code=STATUS_PARAMETER_ERROR,
                                    message="身份证已经注册存在")
    if User.objects.filter(phone_number=phone_number):
        return response_success_200(code=STATUS_PARAMETER_ERROR,
                                    message="手机号码已经注册存在")

    # 验证格式
    if not pd_card(card):
        return response_success_200(code=STATUS_PARAMETER_ERROR,
                                    message="身份证格式错误")
    if qq and not pd_qq(qq):
        return response_success_200(code=STATUS_PARAMETER_ERROR,
                                    message="qq格式不正确")
    if email and not pd_email(email):
        return response_success_200(code=STATUS_PARAMETER_ERROR,
                                    message="email格式不正确")
    if phone_number and not pd_phone_number(phone_number):
        return response_success_200(code=STATUS_PARAMETER_ERROR,
                                    message="手机号格式错误")
Esempio n. 6
0
def check_teacher_insert_info(request):
    school = request.data.get('school')
    title = request.data.get('title')
    card = request.data.get('card')
    phone_number = request.data.get('phone_number')
    name = request.data.get('name')
    qq = request.data.get('qq')
    email = request.data.get('email')

    # 不能为空的数据
    if not card:
        return response_error_400(message="card 不能为空")
    if not name:
        return response_error_400(message="name 不能为空")
    if not phone_number:
        return response_error_400(message="手机号 不能为空")

    # 学校关联
    if not School.objects.filter(id=school):
        return response_error_400(staus=STATUS_PARAMETER_ERROR,
                                  message="学校不存在")
    # 用户检查是否存在
    if UserDetails.objects.filter(card=card):
        return response_error_400(staus=STATUS_PARAMETER_ERROR,
                                  message="身份证已经注册存在")
    if User.objects.filter(phone_number=phone_number):
        return response_error_400(staus=STATUS_PARAMETER_ERROR,
                                  message="手机号码已经注册存在")

    # 验证格式
    if not pd_card(card):
        return response_error_400(message="身份证格式错误")
    if qq and not pd_qq(qq):
        return response_error_400(message="qq格式不正确")
    if email and not pd_email(email):
        return response_error_400(message="email格式不正确")
    if not pd_phone_number(phone_number):
        return response_error_400(message="手机号格式错误")
Esempio n. 7
0
def check_parent_insert_info(request):
    card = request.data.get('card')
    phone_number = request.data.get('phone_number')
    name = request.data.get('name')
    qq = request.data.get('qq')
    email = request.data.get('email')

    # 不能为空的数据
    if not card:
        return response_success_200(message="card 不能为空")
    if not name:
        return response_success_200(message="name 不能为空")
    if not phone_number:
        return response_success_200(message="手机号 不能为空")

    # 用户检查是否存在
    if UserDetails.objects.filter(card=card):
        return response_success_200(staus=STATUS_PARAMETER_ERROR,
                                    message="身份证已经注册存在")
    if User.objects.filter(phone_number=phone_number):
        return response_success_200(staus=STATUS_PARAMETER_ERROR,
                                    message="手机号码已经注册存在")

    # 验证格式
    if not pd_card(card):
        return response_success_200(staus=STATUS_PARAMETER_ERROR,
                                    message="身份证格式错误")
    if qq and not pd_qq(qq):
        return response_success_200(staus=STATUS_PARAMETER_ERROR,
                                    message="qq格式不正确")
    if email and not pd_email(email):
        return response_success_200(staus=STATUS_PARAMETER_ERROR,
                                    message="email格式不正确")
    if not pd_phone_number(phone_number):
        return response_success_200(staus=STATUS_PARAMETER_ERROR,
                                    message="手机号格式错误")
Esempio n. 8
0
    def create(self, request, *args, **kwargs):
        check_token = pd_adm_token(request)
        if check_token:
            return check_token

        # 用户名
        user_name = request.data.get('user_name')
        # 手机号
        phone_number = request.data.get("phone_number")
        # 密码
        password = request.data.get("password")
        # 角色
        role = request.data.get('role')
        # 真实姓名
        name = request.data.get('name')

        if not (role == 0 or role == 1 or role == 2):
            return response_success_200(code=STATUS_PARAMETER_ERROR,
                                        message="role的取值为(0, 1, 2)")

        if not pd_phone_number(phone_number):
            message = "手机号格式错误"
            return response_success_200(code=STATUS_PHONE_NUMBER_DUPLICATE,
                                        message=message)

        if check_user_name(user_name):
            message = "用户名已存在"
            return response_success_200(code=STATUS_USER_NAME_DUPLICATE,
                                        message=message)
        if check_phone_number(phone_number):
            message = "该手机号已被注册"
            return response_success_200(code=STATUS_PHONE_NUMBER_DUPLICATE,
                                        message=message)

        # 创建用户详情 并获得他的id
        user_details_id = UserDetails.objects.create(name=name).id

        # 加密
        request.data["password"] = my_encode(password)
        request.data['user_details'] = user_details_id
        request.data['token'] = "-1"

        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)
        headers = self.get_success_headers(serializer.data)

        # 创建角色信息
        user_id = serializer.data['id']
        if role == 0:
            save_teacher = Teacher(user_id=user_id)
            save_teacher.save()
        elif role == 1:
            save_student = Student(user_id=user_id)
            save_student.save()
        elif role == 2:
            save_parent = Parent(user_id=user_id)
            save_parent.save()
        else:
            message = "角色不存在"
            return response_success_200(status=STATUS_CODE_ERROR,
                                        message=message)
        # data = serializer.data
        print(f'数据是:{serializer.data}')
        return response_success_200(code=STATUS_200_SUCCESS,
                                    data=serializer.data,
                                    headers=headers)
Esempio n. 9
0
    def partial_update_adm(self, request, *args, **kwargs):
        check_token = pd_adm_token(request)
        if check_token:
            return check_token

        user_update = Student.objects.get(pk=kwargs['pk']).user
        phone_number = request.data.get("phone_number")
        if phone_number:
            if phone_number != user_update.phone_number:
                if not pd_phone_number(phone_number):
                    return response_success_200(code=STATUS_PHONE_NUMBER_ERROR,
                                                message="手机号输入有误")
                if User.objects.exclude(pk=user_update.id).filter(
                        phone_number=phone_number):
                    return response_success_200(
                        code=STATUS_PHONE_NUMBER_DUPLICATE, message="手机号已存在")
                user_update.phone_number = phone_number

        # 获得传过来的参数
        user_details = request.data.get('user_details')
        print(user_details)
        # 获得需要修改的userDetails
        user_detail_update = user_update.user_details
        sex = user_details.get('sex')
        name = user_details.get('name')
        birthday = user_details.get('birthday')
        card = user_details.get('card')
        qq = user_details.get('qq')
        email = user_details.get('email')

        if sex and sex is not user_detail_update.sex:
            user_detail_update.sex = sex
        if name and name is not user_detail_update.name:
            user_detail_update.name = name
        if birthday and birthday != user_detail_update.birthday:
            check_time = check_time_stamp(int(birthday))
            print(check_time)
            if check_time:
                return response_success_200(code=STATUS_PARAMETER_ERROR,
                                            message=check_time)
            user_detail_update.birthday = birthday
        if card and card != user_detail_update.card:
            if not pd_card(card):
                return response_success_200(code=STATUS_PARAMETER_ERROR,
                                            message="身份证输入有误")
            if UserDetails.objects.exclude(pk=user_detail_update.id).filter(
                    card=card):
                return response_success_200(code=STATUS_PARAMETER_ERROR,
                                            message="身份证已存在")
            user_detail_update.card = card
        if qq and qq != user_detail_update.qq:
            print(qq)
            print(user_detail_update.qq)
            if not pd_qq(qq):
                return response_success_200(code=STATUS_PARAMETER_ERROR,
                                            message="qq输入有误")
            if UserDetails.objects.exclude(pk=user_detail_update.id).filter(
                    qq=qq):
                return response_success_200(code=STATUS_PARAMETER_ERROR,
                                            message="qq已存在")
            user_detail_update.qq = qq
        if email and email != user_detail_update.email:
            if not pd_email(email):
                return response_success_200(code=STATUS_PARAMETER_ERROR,
                                            message="email输入有误")
            if UserDetails.objects.exclude(pk=user_detail_update.id).filter(
                    email=email):
                return response_success_200(code=STATUS_PARAMETER_ERROR,
                                            message="email已存在")
            user_detail_update.email = email

        # 保存修改
        user_update.save()
        user_detail_update.save()

        resp = super().partial_update(request, *args, **kwargs)

        return response_success_200(data=resp.data)