Ejemplo n.º 1
0
def newcategoryname():
	itemlist=[]
	form = cgi.FieldStorage()
	newcname = form.getvalue("newcategname")
	user = form.getvalue("changeusername")
	categ = form.getvalue("changecategname")
	wrongname = db.GqlQuery("Select * from Category where username = :1 and categoryname = :2",user,newcname)
	message = ""
	if wrongname.count()!=0:
		message = "This category name already exists. Please enter another categoryname"
	else:
		rightname = db.GqlQuery("Select * from Category where username = :1 and categoryname = :2",user,categ)
		voteresults = db.GqlQuery("Select * from Vote where username = :1 and categoryname = :2",user,categ)
		olditemname=""
		oldusername=""
		oldwins=0
		oldloss=0
		for vote in voteresults:
			olditemname=vote.itemname
			oldusername=vote.username
			oldwins=vote.wins
			oldloss=vote.loss
			newvote=Vote(username=oldusername,categoryname=newcname,itemname=olditemname)
			newvote.wins=oldwins
			newvote.loss=oldloss
			newvote.put()
		db.delete(voteresults)
		commentresults = db.GqlQuery("Select * from Comments where owner = :1 and categoryname = :2",user,categ)
		oldowner=""
		oldusername=""
		oldcomment=""
		olditemname=""
		for comments in commentresults:
			oldowner = comments.owner
			oldusername = comments.username
			olditemname = comments.itemname
			oldcomment = comments.comment
			newcomment = Comments(owner=oldowner,username=oldusername,categoryname=newcname,itemname=olditemname)
			newcomment.comment = oldcomment
			newcomment.put()
	        db.delete(commentresults)		
		for result in rightname:
			itemlist = result.items	
		newnamecateg = Category(username=user,categoryname=newcname)
		newnamecateg.items = itemlist
		db.delete(rightname)
		newnamecateg.put()
		message="Category name has been successfully updated to " + newcname
	return render_template("categorynameresult.html",output=message)
Ejemplo n.º 2
0
def storevotes():
	form = cgi.FieldStorage()
	button = form.getvalue("submitvote")
	voteitem = form.getvalue("votechoice")
	itemone = form.getvalue("itemone")
	itemtwo = form.getvalue("itemtwo")
	winner = ""
	loser = ""
	if itemone==voteitem:
		winner = itemone
		loser = itemtwo
	else:
		winner = itemtwo
		loser = itemone
	currentuser = users.get_current_user()
	nickname = currentuser.nickname()
	categowner = form.getvalue("categoryowner")
	categname = form.getvalue("categoryname")
	if button=="Vote":
		message = "" 
		resultset = db.GqlQuery("Select * from Vote where username = :1 and categoryname = :2 and itemname = :3",categowner,categname,winner)
		if resultset.count()==0:
			newvote = Vote(username=categowner,categoryname=categname,itemname=winner)
			newvote.wins=1
			newvote.loss=0
			newwins = 1;
			newvote.put()
		else:
			newwins = 0
			oldloss = 0
			for result in resultset:
				oldloss = result.loss
				newwins = result.wins + 1
			db.delete(resultset)
			newvote = Vote(username=categowner,categoryname=categname,itemname=winner)
			newvote.wins = newwins
			newvote.loss = oldloss
			newvote.put()
		loserresultset = db.GqlQuery("Select * from Vote where username = :1 and categoryname = :2 and itemname = :3",categowner,categname,loser)
		if loserresultset.count()==0:
			newloss = Vote(username=categowner,categoryname=categname,itemname=loser)
			newloss.wins=0
			newloss.loss=1
			losses=1
			newloss.put()
		else:
			losses=0
			oldwins=0
			for lresult in loserresultset:
				oldwins = lresult.wins
				losses = lresult.loss + 1
			db.delete(loserresultset)
			newloss = Vote(username=categowner,categoryname=categname,itemname=loser)
			newloss.wins= oldwins
			newloss.loss = losses
			newloss.put()
		return render_template('results.html',wins=newwins,lossesn=losses,categ=categname,winitem=winner,lossitem=loser,fmessage=message)
	else:	
		return render_template('postcomments.html',user1=nickname,owner=categowner,categ=categname,item=voteitem)