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)
def savecomments(): user = users.get_current_user() nickname = user.nickname() form = cgi.FieldStorage() owner1 = form.getvalue("owner") categ = form.getvalue("cname") itemname1 = form.getvalue("itemname") comments = form.getvalue("thecomment") response="" resultset = db.GqlQuery("Select * from Comments where owner = :1 and username = :2 and categoryname = :3 and itemname = :4",owner1,nickname,categ,itemname1) if resultset.count()==0: newcomment = Comments(owner=owner1,username=nickname,categoryname=categ,itemname=itemname1) newcomment.comment = comments newcomment.put() response = "Your comment has been successfully stored" else: response = "You have already commented on this item before. you are not allowed to comment on the same item again. Thank you" return render_template("commentresponse.html",status=response,item=itemname1)