def validate_candidate(request): # ht print "\nin the function add_candidate\n" if request.method == 'POST': form = CandidateForm(request.POST) if form.is_valid(): print "\nform is_valid\n" candidate = form.save(commit=False) try: voter = Voter.objects.get(voterid=candidate.voterid) except: print "\nIncorrect VoterID\n" return HttpResponse("Voter ID does not exist !") # render a proper message on UI candidate.candidateid = 'CI' + encode(Candidate.objects.count()+1) print "\nhere\n" user = User(username=candidate.candidateid,password=candidate.password) user.set_password(user.password) user.save() candidate.save() print "form: ",form return HttpResponseRedirect('/electoraldb/candidate_success/?username=%s&password=%s' %(candidate.candidateid,candidate.password)) else: print "errors ",form.errors else: #request was not post method type form = CandidateForm() # to render return HttpResponseRedirect('/electoraldb/add_candidate/')
def add_candidate(request): # ht if request.method == 'POST': data = request.POST form = CandidateForm(request.POST) #is the form valid? if form.is_valid(): candidate = form.save(commit=False) print form candidate.candidateid = 'CI' + encode(Candidate.objects.count()+1) candidate.save() return index(request) else: print form.errors else: #request was not post method type form = CandidateForm() return render(request,'electoraldb/add_candidate.html',{'form':form})
def add_candidate(request): # ht print "\nin the function add_candidate\n" if request.method == 'POST': form = CandidateForm(request.POST, request.FILES) if form.is_valid(): print "\nform is_valid\n" candidate = form.save(commit=False) candidate.candidateid = 'CI' + encode(Candidate.objects.count()+1) print "\nhere\n" candidate.save() print "form: ",form return index(request) # jump to index.html else: print "errors ",form.errors else: #request was not post method type form = CandidateForm() # to render return render(request,'electoraldb/add_candidate.html',{'form':form})