OJ2.0userInfo page Modify logic bug fixes, search function logic implementation

Source: Internet
Author: User

OJ2.0userInfo page Modify logic bug fixes, search function logic implementation

This week's main task is to fix the Modify logic bug on the userInfo page and implement the search function logic.

(1) Modify logic bug fixing:

The bug here is that when we do not reset the password, we cannot submit changes according to the previous logic. This logic is incorrect and can be submitted without changing the password, it mainly refers to the modification of if logic judgment.

First look at the Code:

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':{} })

By the way, the last time there was another question: how to determine which button to submit when there are multiple buttons in a form, for example, the current userInfo page has Modify and Search buttons, so how can we determine whether

Which one is submitted. After checking on the Internet, one solution is to mark different names for different submit, and then if the request. POST. if has_key ("Modify") is set up, the Modify button is submitted. Otherwise

This is the submission of Search. This method is more practical.

For the above Modify logic, the main problem is to first determine if the password and confirmpassword are the same and are not empty, submit the modification. When the two are different, the error message is displayed. When determining that the two are the same

If it is null, submit the modification. This is in line with the actual situation.

(2) Implementation of UserInfo page search:

As predicted last week, a user's search is implemented on the UserInfo page. In fact, the search principle is similar to that of problemList. When there are multiple buttons in a form, it is a logical judgment.

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':{} })

When we determine a request from Search, we first use request. POST ["idname"] to obtain the input query conditions from the page. Initialize the user object set and then use fuzzy query (attribute name _ contains = Query

Note that the underline is composed of two underscores. Then, when we obtain a set that meets the query requirements, it is passed back to the page. Then, the page displays:

      
 
 
    {%for u in users %} 
    {% endfor %} 
  
UserId Username
{{u.userID}} {{u.nickname}}

Here, a Table is generated to store the results, and a {% for u in users %} result is displayed cyclically. A table is generated. The current design is to click a display item and adjust it to the userInfo page.

But there is no query result.

Then the main task of this week is just a little bit of code. This week's progress is a little slow ........ We hope that the subsequent tasks will catch up.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.