OJ2.0userInfo页面Modify逻辑bug修复,search功能逻辑实现
2014-08-12 21:52
369 查看
这周的主要任务:userInfo页面Modify逻辑bug修复,search功能逻辑实现。
(一)Modify逻辑bug修复:
这里存在的bug就是在我们不重置密码的时候按照前面的逻辑是不能提交修改,这个逻辑是错误的,应该改为可以不修改密码也能提交,主要是if逻辑判断的修改
先看一下代码:
def userInfo(request, user_id):
try:
user = User.objects.get(userID = request.session['userID'])
except:
return HttpResponseRedirect("/index/login")
other = User.objects.get(userID = user_id)
if request.method == 'POST':
if request.POST.has_key("Modify"):
userID = request.session['userID']
oldPassword = request.POST['oldPassword']
password = request.POST['password']
confirmPassword = request.POST['confirmPassword']
session = request.POST['session']
specialty = request.POST['specialty']
tel = request.POST['tel']
email = request.POST['email']
nickname = request.POST['nickname']
if oldPassword != user.password:
return HttpResponse("password error")
else:
user.password = oldPassword
user.session = session
user.specialty = specialty
user.tel = tel
user.email = email
user.nickname = nickname
if password.strip() != '' and password == confirmPassword:
user.password = password
user.save()
other = User.objects.get(userID = user_id)
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'],'user': user, 'other':other})
else:
if password != confirmPassword:
return HttpResponse("password and confirmPassword is not the same!")
else:
user.save()
other = User.objects.get(userID = user_id)
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'], 'user':user, 'other':other})
else:
users = User.objects.all()
userid = request.POST['idname']
try:
if userid.strip():
users = users.filter(userID__contains = userid)
#return HttpResponse(users
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'], 'user': user, 'other':other, 'users':users, 'idname':userid })
except :
#return HttpResponse("fuck")
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'],'user': user, 'other':other, 'users':{} })
else:
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'],'user': user, 'other':other, 'users':{} })
对了,上次还有一个问题就是在一个表单中有多个按钮的时候如何判断是哪一个按钮的提交,比如当前的userInfo页面有Modify和Search两个按钮,那么如何判断到底是
哪一个的提交呢。在网上查了一下,一种解决方法就是给不同的submit标记不同的name,然后再如果request.POST.has_key("Modify")成立就代表提交的是Modify按钮,否则的
话就是Search的提交了。这种方法还是比较实用的。
对于上述的Modify的逻辑的问题,主要就是先判断如果password和confirmpassword相同且不空的时候,提交修改。在判断两者不相同的时候错误提示。在判断两者同为
空的时候提交修改。这样就符合实际的情况了。
(二):UserInfo页面搜索实现:
按照上周的预计,是要在UserInfo页面实现一个用户的搜索,其实原理和problemList的搜索差不多。当我们解决了一个表单中有多个按钮的时候,那么就是一个逻辑判断而已。
if request.POST,has_key("Modify") else 执行搜索的过程:
users = User.objects.all()
userid = request.POST['idname']
Nickname = request.POST['idname']
try:
if userid.strip():
users = users.filter(userID__contains = userid)
#return HttpResponse(users)
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'], 'user': user, 'other':other, 'users':users, 'idname':userid })
except :
#return HttpResponse("fuck")
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'],'user': user, 'other':other, 'users':{} })
当我们判断是来自Search的请求时,首先使用request.POST["idname"]从页面取出来输入的查询条件。然后初始化user对象集合,然后使用模糊查询(属性名__contains = 查询
条件),注意这里的下划线是两个下划线组成的。然后当我们获得符合查询要求的集合后就传回到页面。再在页面展示:
<div class = "table-responsive" style = "padding-top:58px">
<table cellpadding = "10" cellspacing = "0" class = "display" id = "example">
<thead>
<tr>
<th>UserId</th>
<th>Username</th>
</tr>
</thead>
<tbody>
{%for u in users %}
<tr class="odd gradeX">
<td> <a href = "/index/userInfo/{{u.userID}}">{{u.userID}} </a> </td>
<td>{{u.nickname}} </td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
这里生成了一个Table存放查出来的结果,然后一个{% for u in users %}循环展式查询到的结果。就会生成一个表。然后现在的设计是点击某一个展示项的,调到userInfo页
面,不过没有了查询结果而已。
然后这周主要的任务也就这么点代码而已。这周进度有点慢.......。希望后面的任务能够赶上去。
(一)Modify逻辑bug修复:
这里存在的bug就是在我们不重置密码的时候按照前面的逻辑是不能提交修改,这个逻辑是错误的,应该改为可以不修改密码也能提交,主要是if逻辑判断的修改
先看一下代码:
def userInfo(request, user_id):
try:
user = User.objects.get(userID = request.session['userID'])
except:
return HttpResponseRedirect("/index/login")
other = User.objects.get(userID = user_id)
if request.method == 'POST':
if request.POST.has_key("Modify"):
userID = request.session['userID']
oldPassword = request.POST['oldPassword']
password = request.POST['password']
confirmPassword = request.POST['confirmPassword']
session = request.POST['session']
specialty = request.POST['specialty']
tel = request.POST['tel']
email = request.POST['email']
nickname = request.POST['nickname']
if oldPassword != user.password:
return HttpResponse("password error")
else:
user.password = oldPassword
user.session = session
user.specialty = specialty
user.tel = tel
user.email = email
user.nickname = nickname
if password.strip() != '' and password == confirmPassword:
user.password = password
user.save()
other = User.objects.get(userID = user_id)
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'],'user': user, 'other':other})
else:
if password != confirmPassword:
return HttpResponse("password and confirmPassword is not the same!")
else:
user.save()
other = User.objects.get(userID = user_id)
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'], 'user':user, 'other':other})
else:
users = User.objects.all()
userid = request.POST['idname']
try:
if userid.strip():
users = users.filter(userID__contains = userid)
#return HttpResponse(users
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'], 'user': user, 'other':other, 'users':users, 'idname':userid })
except :
#return HttpResponse("fuck")
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'],'user': user, 'other':other, 'users':{} })
else:
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'],'user': user, 'other':other, 'users':{} })
对了,上次还有一个问题就是在一个表单中有多个按钮的时候如何判断是哪一个按钮的提交,比如当前的userInfo页面有Modify和Search两个按钮,那么如何判断到底是
哪一个的提交呢。在网上查了一下,一种解决方法就是给不同的submit标记不同的name,然后再如果request.POST.has_key("Modify")成立就代表提交的是Modify按钮,否则的
话就是Search的提交了。这种方法还是比较实用的。
对于上述的Modify的逻辑的问题,主要就是先判断如果password和confirmpassword相同且不空的时候,提交修改。在判断两者不相同的时候错误提示。在判断两者同为
空的时候提交修改。这样就符合实际的情况了。
(二):UserInfo页面搜索实现:
按照上周的预计,是要在UserInfo页面实现一个用户的搜索,其实原理和problemList的搜索差不多。当我们解决了一个表单中有多个按钮的时候,那么就是一个逻辑判断而已。
if request.POST,has_key("Modify") else 执行搜索的过程:
users = User.objects.all()
userid = request.POST['idname']
Nickname = request.POST['idname']
try:
if userid.strip():
users = users.filter(userID__contains = userid)
#return HttpResponse(users)
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'], 'user': user, 'other':other, 'users':users, 'idname':userid })
except :
#return HttpResponse("fuck")
return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'],'user': user, 'other':other, 'users':{} })
当我们判断是来自Search的请求时,首先使用request.POST["idname"]从页面取出来输入的查询条件。然后初始化user对象集合,然后使用模糊查询(属性名__contains = 查询
条件),注意这里的下划线是两个下划线组成的。然后当我们获得符合查询要求的集合后就传回到页面。再在页面展示:
<div class = "table-responsive" style = "padding-top:58px">
<table cellpadding = "10" cellspacing = "0" class = "display" id = "example">
<thead>
<tr>
<th>UserId</th>
<th>Username</th>
</tr>
</thead>
<tbody>
{%for u in users %}
<tr class="odd gradeX">
<td> <a href = "/index/userInfo/{{u.userID}}">{{u.userID}} </a> </td>
<td>{{u.nickname}} </td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
这里生成了一个Table存放查出来的结果,然后一个{% for u in users %}循环展式查询到的结果。就会生成一个表。然后现在的设计是点击某一个展示项的,调到userInfo页
面,不过没有了查询结果而已。
然后这周主要的任务也就这么点代码而已。这周进度有点慢.......。希望后面的任务能够赶上去。
相关文章推荐
- OJ2.0userInfo页面Modify逻辑bug修复,search功能逻辑实现
- nutch的查询结果页面search.jsp如何实现翻页功能
- 如何在App中实现朋友圈功能之八页面加载功能的逻辑与实现——箭扣科技Arrownock
- 如何在App中实现朋友圈功能之八页面加载功能的逻辑与实现——箭扣科技Arrownock
- 实现复制表单功能(逻辑+页面开发详细说明)
- ASP.NET MVC 学习4、Controller中添加SearchIndex页面,实现简单的查询功能
- 多框架 跨页面调用jsp过程,实现功能导航树的隐藏
- 页面定时刷新功能实现
- 跨页面的多选功能实现
- 一段实现DataGrid的“编辑”、“取消”功能脚本,目的是不产生页面刷新
- JQuery简便实现页面元素数据验证功能
- 页面定时刷新功能实现
- (转)XML HTTP实现无刷新页面功能
- JQuery 简便实现页面元素数据验证功能
- 使用Web Datawindow ActiveX实现Web页面的打印功能
- 在ASP.NET页面中实现数据库备份和恢复功能
- Ajax程序中,自己实现页面前进、后退、与标签功能(asp.net2.0)
- 一种简单方法实现页面导出(Excel)功能
- Ajax程序中,自己实现页面前进、后退、与标签功能(asp.net2.0)
- javascript实现加载页面全屏以及禁用鼠标右键和选取功能