Пример #1
0
def read_xls(self, request, obj, change):
    print(obj.file)
    df = pandas.read_excel(obj.file)
    print(df)
    # df.drop([0],inplace=True)
    # df.columns = ['username','sex','age']
    for i in range(0, len(df['学工号'])):
        username = df.iloc[i, 0]
        email = df.iloc[i, 1]
        professor = df.iloc[i, 2]
        jidian = df.iloc[i, 3]
        password = 123456
        role_id = df.iloc[i, 4]
        #导入用户信息
        role = Role.objects.get(id=role_id)
        user = User()
        user.username = username
        user.role = role
        user.professor = professor
        user.email = email
        user.set_password(password)
        user.is_active = 1
        user.save()
        #导入绩点信息
        rate_jidians = Work_rate_jidian.objects.get(pro_name=professor)
        id = User.objects.get(username=username).id
        Work_count.objects.create(usernum=id,
                                  count_jidians=jidian,
                                  rate_jidians=rate_jidians)
    return 'success'
Пример #2
0
    def post(self, request):
        # 1.获取参数
        user_num = request.POST.get('user_num')
        password = request.POST.get('pwd')
        professor = request.POST.get('cpwd')
        email = request.POST.get('email')
        role_id = request.POST.get('loc')
        print(role_id)
        # 2.校验参数完整性
        if not all([user_num, password, professor, email, role_id]):
            return render(request, 'register.html', {'errmsg': '数据不完整,请重新输入'})
        # 2.1校验邮箱是否合法
        # 校验邮箱
        if not re.match(r'^[a-z0-9][\w.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$',
                        email):
            return render(request, 'register.html', {'errmsg': '邮箱格式不正确'})
        # 2.2校验用户是否存在
        try:
            user = User.objects.get(user_num=user_num)
        except User.DoesNotExist:
            # 用户不存在
            user = None
        if user:
            # 用户名已存在
            return render(request, 'register.html', {'errmsg': '用户名已存在'})

        # 3.业务处理,进行注册操作
        role = Role.objects.get(id=role_id)
        user = User()
        user.username = user_num
        user.role = role
        user.professor = professor
        user.email = email
        user.set_password(password)
        user.is_active = 0
        user.save()

        # 注册成功需要通过邮箱返回激活链接
        # 使用itsdangerous生成激活的token信息
        seeializer = Serializer(settings.SECRET_KEY, 3600)
        info = {'confirm': user.id}
        # 进行加密
        token = seeializer.dumps(info)
        # 转换类型
        token = token.decode()
        # 组织邮件内容
        send_mail_register(email, user_num, token)
        # 返回应答

        # 4.返回响应
        return render(request, 'login.html')