Beispiel #1
0
def registerVote():
	form = cgi.FieldStorage();
	if(form.has_key('vote')):
		voteon = form['voteon'].value;
		vote = voteon.replace("__"," ");
		surveyName = form['survey'].value;
		survey = surveyName.replace("__"," ");
		user = form['user'].value.strip();
		tempUser = user;
		if not "@" in tempUser:
			tempUser = tempUser + "@gmail.com";
		user1 = users.User(tempUser);
		voter = users.get_current_user();
		surveyData = db.GqlQuery("SELECT * FROM Survey WHERE name =:1 and owner =:2",survey,user1);
		expireDate="";
		for sur in surveyData:
			expireDate = sur.expiration;
		if (expireDate < datetime.datetime.now()):
			return render_template('failure.html',message="This survey has expired. You can still view its result!");
		winnerVote = db.GqlQuery("SELECT * FROM Vote WHERE owner = :1 and survey = :2 and name = :3",user1,survey,vote);
		win_number = 1;
		for i in winnerVote:
				win_number = i.win;
				win_number += 1;
		db.delete(winnerVote);
		newVote = Vote(name=vote,survey=survey,owner=user1,win=win_number);
		newVote.put();
		return render_template('successful_voting.html',winner=vote,looser=" All Others.");
		
	else:
		voteon = form['voteon'].value;
		vote = voteon.replace("__"," ");
		survey = form['survey'].value;
		surveyName = survey.replace("__"," ");
		user = form['user'].value.strip();
		tempUser = user;
		if not "@" in tempUser:
			tempUser = tempUser + "@gmail.com";
		user1 = users.User(tempUser);
		commenter = users.get_current_user();
		isCommented = db.GqlQuery("SELECT * FROM CommentValidator WHERE itemName = :1 AND itemOwner = :2 AND survey = :3 AND commenter = :4",vote,user1,surveyName,commenter);
		counter = isCommented.count();
		if(counter == 0):
				previousComment = db.GqlQuery("SELECT * FROM Comments WHERE itemName = :1 AND itemOwner = :2 AND survey = :3",vote,user1,surveyName);
				comment1 = "";
				for pre in previousComment:
					comment1 = pre.comment;
				newComment = comment1+str(commenter) + " said: "+form['commentText'].value + "; ";
				comment = Comments(itemName=vote,itemOwner=user1,survey=surveyName,comment=newComment);
				commentValidator = CommentValidator(itemName=vote,itemOwner=user1,survey=surveyName,commenter=commenter);
				db.delete(previousComment);
				comment.put();
				commentValidator.put();
				return render_template('failure.html',message="Comment successfully added!");
		else:
				return render_template('failure.html',message="You already have commented on this item!");
Beispiel #2
0
def renameCategory():
	form = cgi.FieldStorage();
	user = users.get_current_user();
	newSurveyName = form['renameText'].value.strip();
	oldSurveyName = form['renamesurvey'].value;
	newNameCheck = db.GqlQuery("SELECT * FROM Survey WHERE owner = :1 AND name = :2",user,newSurveyName);
	counter = newNameCheck.count();
	if (counter > 0):
			return render_template('failure.html',message="You already have a survey with given name. Please try with some other name");
	else:
		oldSurvey = db.GqlQuery("SELECT * FROM Survey WHERE owner = :1 AND name = :2",user,oldSurveyName);
		for old in oldSurvey:
			newSurvey = Survey(name=newSurveyName,values=old.values,owner=old.owner,expiration=old.expiration);
			newSurvey.put();
		oldItems = db.GqlQuery("SELECT * FROM Item WHERE survey = :1 and owner = :2",oldSurveyName,user);
		for old in oldItems:
			newItem = Item(name=old.name,image=old.image,survey=newSurveyName,owner=old.owner);
			newItem.put();
		oldVotes = db.GqlQuery("SELECT * FROM Vote WHERE survey = :1 and owner = :2",oldSurveyName,user);
		for old in oldVotes:
			newVote = Vote(name=old.name,owner=old.owner,win=old.win,survey=newSurveyName);
			newVote.put();
		oldComments = db.GqlQuery("SELECT * FROM Comments WHERE itemOwner = :1 AND survey = :2",user,oldSurveyName);
		for old in oldComments:
			newComment = Comments(itemName=old.itemName,itemOwner=old.itemOwner,comment=old.comment,survey=newSurveyName);
			newComment.put();
		oldCommentValidator = db.GqlQuery("SELECT * FROM CommentValidator where itemOwner = :1 and survey = :2",user,oldSurveyName);
		for old in oldCommentValidator:
			newCommentValidator = CommentValidator(itemName=old.itemName,itemOwner=old.itemOwner,commenter=old.commenter,survey=newSurveyName);
			newCommentValidator.put();
		oldSearch = db.GqlQuery("SELECT * FROM  Search WHERE survey = :1 AND owner = :2",oldSurveyName,user);
		for old in oldSearch:
			if(old.entityType == "survey"):
				newSearch = Search(name=newSurveyName,entityType=old.entityType,survey=newSurveyName,owner=old.owner);
				newSearch.put();
			else:
				newSearch = Search(name=old.name,entityType=old.entityType,survey=newSurveyName,owner=old.owner);
				newSearch.put();
		deleteGeneric(surveyName=oldSurveyName);
		return render_template('failure.html',message="Update Successful!");