def reNewUser(request): #普通的表单项 userName = request.POST.get('userName', '') userPwd = request.POST.get('userPwd', '') userPhone = request.POST.get('userPhone', '') userIntro = request.POST.get('userIntro', '') userPicPath = "" #保存路径 print(userName) print(userPwd) print(userPhone) print(userIntro) #加密密码 userPwd = hashlib.md5(userPwd.encode(encoding='utf-8')).hexdigest() #文件上传 if request.POST: fileObj = request.FILES.get('userPic', None) if fileObj: print("pic成功") userPicPath = '/static/upload/' + fileObj.name print(userPicPath) filePath = os.path.join(os.getcwd(), 'static/upload/' + fileObj.name) with open(filePath, 'wb+') as fp: for chunk in fileObj.chunks(): fp.write(chunk) userDao = UserDao() result = userDao.createUser( [userName, userPwd, userPhone, userPicPath, userIntro]) userDao.commit() userDao.close() #如果写入成功 跳转到登陆页 if result == 1: return render(request, 'admin/login.html', {'success': 1}) pass else: return render(request, 'newuser.html', {'success': 0})
def getUserList(request): userDao = UserDao() # 获取查询条件 userName = request.POST.get('userName', '') userPhone = request.POST.get('userPhone', '') userState = request.POST.get('userState', '') pageSize = request.POST.get('pageSize', '0') currentPage = request.POST.get('currentPage', '0') userId = request.POST.get('userId', '') print(userId) opr = request.POST.get('opr', '') if pageSize == "0" or pageSize == "": pageSize = "3" if currentPage == "0" or currentPage == "": currentPage = "1" print(type(pageSize)) params = { 'userName': userName, 'userPhone': userPhone, 'userState': userState, 'pageSize': int(pageSize), 'currentPage': int(currentPage) } if opr == 'delUser': result = userDao.removeUser(userId) params['result'] = result #查询用户的个人信息 if opr == 'update': uUser = userDao.findUserByUserId([userId]) return render(request, 'admin/sysmgr/updateuser.html', { 'params': params, 'uUser': uUser }) pass #提交用户的个人信息 if opr == 'submitUpdate': print("修改") print(userId) userIntro = request.POST.get('userIntro', '') # 文件上传 userPicPath = "" if request.POST: fileObj = request.FILES.get('userPic', None) if fileObj: userPicPath = '/static/upload/' + fileObj.name filePath = os.path.join(os.getcwd(), 'static/upload/' + fileObj.name) with open(filePath, 'wb+') as fp: for chunk in fileObj.chunks(): fp.write(chunk) result = userDao.updateUser( [userPhone, userPicPath, userIntro, userId]) pass counts = userDao.findUserCounts(params) totalePage = counts // int(pageSize) if counts % int( pageSize) == 0 else counts // int(pageSize) + 1 params['counts'] = counts params['totalPage'] = totalePage #计算两个值 startRow startRow = (int(currentPage) - 1) * int(pageSize) params['startRow'] = startRow userList = userDao.findPageUserList(params) userDao.commit() userDao.close() return render(request, 'admin/sysmgr/userinfo.html', { 'userList': userList, 'params': params })