def validate_party(request):
    # ht
    print "\nin the function\n"
    if request.method == "POST":
        form = PartyForm(request.POST, request.FILES)
        if form.is_valid():
            print "\nis_valid\n"
            party = form.save(commit=False)
            party.partyid = "PI" + encode(Party.objects.count() + 1)
            print "\nhere\n"
            user = User(username=party.partyid, password=party.password)
            user.set_password(user.password)
            user.save()
            party.save()
            print "form: ", form
            return HttpResponseRedirect(
                "/electoraldb/party_success/?username=%s&password=%s" % (party.partyid, party.password)
            )
        else:
            print "errors ", form.errors
    else:
        # request was not post method type
        form = PartyForm()
        # to render
    return render(request, "electoraldb/add_party.html", {"form": form})
Exemple #2
0
def add_party(request):
	# ht
	if request.method == 'POST': 	
		data = request.POST
		form = PartyForm(request.POST)
		#is the form valid?
		if form.is_valid():
			party = form.save(commit=False)
			print form
			party.partyid = 'PI' + encode(Party.objects.count()+1)
			party.save()
			return index(request)
		else:
			print form.errors
	else:
		#request was not post method type
		form = PartyForm()
	return render(request,'electoraldb/add_party.html',{'form':form})
Exemple #3
0
def add_party(request):
	# ht
	print "\nin the function\n"
	if request.method == 'POST': 	
		form = PartyForm(request.POST, request.FILES)
		if form.is_valid():
			print "\nis_valid\n"
			party = form.save(commit=False)
			party.partyid = 'PI' + encode(Party.objects.count()+1)
			print "\nhere\n"
			party.save()
			return index(request)			# jump to index.html
		else:
			print "errors ",form.errors
	else:
		#request was not post method type
		form = PartyForm()
	# to render 
	return render(request,'electoraldb/add_party.html',{'form':form})