def edituser(request,username): user = request.user internaluser = InternalUser.objects.get(mainUserID = user.id) if request.method == "POST": print "1" userform = UserForm(data=request.POST, usertype=1, instance=user) print "2" print userform internaluserform = InternalUserForm(request.POST, instance=internaluser) print "3" print internaluserform if userform.is_valid() and internaluserform.is_valid(): print "4" userform.save() print "5" internaluserform.save() print "6" return HttpResponseRedirect(reverse('ats:userprofile', args=(user.username,))) else: print "7" print userform.errors print internaluserform.errors print "9" return render(request,htmlPageMap['editUser'],{'userform':userform,'internaluserform':internaluserform,'userformerrors':userform.errors,'internaluserformerrors':internaluserform.errors}) else: print "8" userform = UserForm(instance=user) internaluserform = InternalUserForm(instance=internaluser) return render(request,htmlPageMap['editUser'],{'userform':userform,'internaluserform':internaluserform})
def adduser(request): try: currentuser = request.user internaluser = InternalUser.objects.get(mainUserID = currentuser.id) if internaluser.usertype == 1: if request.method == "POST": userform = UserForm(data=request.POST,usertype=1) internaluserform = InternalUserForm(request.POST) if userform.is_valid() and internaluserform.is_valid(): password = request.POST.get('password') confirmpassword = request.POST.get('confirmpassword') if password != confirmpassword: return render(request,htmlPageMap['adduser'],{'userform':userform, 'internaluserform':internaluserform, 'error_msg':'Passwords dont match'}) email = request.POST.get('email') if email: try: user = User.objects.get(email=email) except: user = None if user:#duplicate found return render(request,htmlPageMap['adduser'],{'userform':userform, 'internaluserform':internaluserform, 'error_msg':'User with this email already exists.'}) user = userform.save() user.set_password(user.password) user.save() internaluser = internaluserform.save(commit=False) internaluser.mainUserID = user if 'profilepic' in request.FILES: internaluser.profilepic = request.FILES['profilepic'] internaluser.save() return HttpResponseRedirect(reverse('ats:confirm', args=(user.id,))) else: return render(request,htmlPageMap['adduser'],{'userform':userform, 'internaluserform':internaluserform, 'error_msg': str(userform.errors)+ "; " + str(internaluserform.errors) }) else: userform = UserForm() internaluserform = InternalUserForm() return render(request,htmlPageMap['adduser'],{'userform':userform, 'internaluserform':internaluserform}) else: return HttpResponseRedirect(reverse('ats:userprofile', args=(currentuser.username,))) except: print ("Exception Occured")
def register(request): if request.method =="POST": userform = UserForm(data=request.POST,usertype=0) candidateform = CandidateForm(request.POST) if userform.is_valid() and candidateform.is_valid(): if request.POST.get('password') != request.POST.get('confirmpassword'): return render(request,htmlPageMap['register'],{'userform':userform,'candidateform':candidateform,'error_msg':'Password Mismatch'}) user = userform.save(commit=True) user.set_password(user.password) user.save() candidate = candidateform.save(commit=False) candidate.mainUserID = user if "profilepic" in request.FILES: candidate.profilepic = request.FILES['profilepic'] if "resumefile" in request.FILES: candidate.resumefile = request.FILES['resumefile'] candidate.save() return login_and_authenticate(request,user.username,request.POST.get('password')) else: return render(request,htmlPageMap['register'],{'userform':userform,'candidateform':candidateform,'userformerror':userform.errors,'candidateformerror':candidateform.errors}) else: userform = UserForm() candidateform = CandidateForm() return render(request,htmlPageMap['register'],{'userform':userform,'candidateform':candidateform})