Esempio n. 1
0
def add_voter(request):
	# ht
	
	if request.method == 'POST':
		data = request.POST
		print data
		form = VoterForm(request.POST)
		#print form
		#is the form valid?
		if form.is_valid():						
			voter = form.save(commit=False)
			voter.voterid = 'VW'+encode(Voter.objects.count()+1)
			i = datetime.now()
			voter.doa = str(i.year)+"-"+str(i.month)+"-"+str(i.day)
			voter.partno = 'NEWPART'
			voter.picno = "PICNO"			
			x =  Address.objects.get(pin=data['pin'],town=data['town'])
			print x
			voter.pin = Address.objects.get(pin=data['pin'],town=data['town'])
			voter.town =Address.objects.get(pin=data['pin'],town=data['town'])
			voter.save()
			print voter.town.town
			return index(request)
		else:
			print form.errors
	else:
		#request was not post method type
		form = VoterForm()
	return render(request,'electoraldb/add_voter.html',{'form':form})
Esempio n. 2
0
def validate_candidate(request):
	if request.method == 'POST':
		data = request.POST
		print data
		form = VoterForm(request.POST)
		#print form
		#is the form valid?
		if form.is_valid():						
			voter = form.save(commit=False)
			voter.voterid = 'VW'+encode(Voter.objects.count()+1)
			i = datetime.now()
			voter.doa = str(i.year)+"-"+str(i.month)+"-"+str(i.day)
			voter.partno = 'NEWPART'
			voter.picno = "PICNO"			
			x =  Address.objects.get(pin=data['pin'],town=data['town'])
			print x
			voter.pin = Address.objects.get(pin=data['pin'],town=data['town'])
			voter.town =Address.objects.get(pin=data['pin'],town=data['town'])
			voter.save()
			print voter.town.town
			return index(request)
		else:
			print form.errors
	else:
		#agar koi hacker hoo toh
		pass
	return render(request,'electoraldb/candidate.html')
def validate_voter(request):
    # ht

    if request.method == "POST":
        data = request.POST
        print data
        form = VoterForm(request.POST)

        # print form
        # is the form valid?
        if form.is_valid():
            voter = form.save(commit=False)
            voter.voterid = "VW" + encode(Voter.objects.count() + 1000)
            age = datetime.now().year - voter.dob.year
            print age
            if age < 18:
                print "Enter age greater than 18"  # handle the front end here
                return HttpResponse("Invalid Age : Age is less than 18")
            elif voter.town == "----":
                print "Enter Correct PIN"
                return HttpResponse("Invalid Age : Pin incorrect")  # handle the front end here
            else:
                user = User(username=voter.voterid, password=voter.password)
                user.set_password(user.password)
                user.save()
                i = datetime.now()
                voter.doa = str(i.year) + "-" + str(i.month) + "-" + str(i.day)
                voter.partno = Polling.objects.filter(town=voter.town)[0].partno
                voter.picno = "PICNO"
                voter.approved = "false"
                voter.save()
                # print voter.town
                return HttpResponseRedirect(
                    "/electoraldb/voter_success/?username=%s&password=%s" % (voter.voterid, voter.password)
                )
        else:
            print form.errors
    else:
        # request was not post method type
        form = VoterForm()
    return render(request, "electoraldb/add_voter.html", {"form": form})