Exemplo n.º 1
0
def moddate():
	form = cgi.FieldStorage()
	month = form.getvalue("Month")
	day = form.getvalue("day")
	year = form.getvalue("year")
	hour = form.getvalue("hour")
	minutes = form.getvalue("min")
	#ampm = form.getvalue("ampm")
	user = form.getvalue("dateuser")
	categ = form.getvalue("datecateg")
	hour1=int(hour)
	#if str(ampm)=="pm":
	#	hour1 = int(str(hour))
	#	hour1 = hour1 + 12
	day1 = int(str(day))
	year1 = int(str(year))
	month1 = int(str(month))
	minutes1 = int(str(minutes))
	date = datetime.datetime(year1,month1,day1,hour1,minutes1)
	resultset = db.GqlQuery("Select * from Category where username = :1 and categoryname = :2",user,categ)
	itemlists = []
	for result in resultset:
		itemlists = result.items
	newCategory=Category(username=user,categoryname=categ)
	newCategory.items = itemlists
	newCategory.expirydate = date
	db.delete(resultset)
	newCategory.put()
	newdate = datetime.datetime(2012,4,3,10,12)
	dateresult = db.GqlQuery("Select * from Category where username = :1 and categoryname = :2",user,categ)
	for result in dateresult:
		newdate = result.expirydate
	return render_template("moddate.html",dateobj=newdate)
Exemplo n.º 2
0
def deleteedititems():
	form = cgi.FieldStorage()
	itemstobedeleted = form.getvalue("deleteitemnames")
	user = form.getvalue("deleteuser")
	categ = form.getvalue("deletecateg")
	oldresultset = db.GqlQuery("Select * from Category where username = :1 and categoryname = :2",user,categ)
	olditems = []
	for result in oldresultset:
		olditems = result.items
	newlistitems = []
	rejectitems = []
	for item in olditems:
		if item in itemstobedeleted:
			rejectitems.append(item)
		else:
			newlistitems.append(item)
	deleteset = db.GqlQuery("Select * from Vote where username = :1 and categoryname = :2 and itemname in :3",user,categ,rejectitems)
	db.delete(deleteset)
	db.delete(oldresultset)
	newcategoryadd = Category(username=user,categoryname=categ)
	newcategoryadd.items = newlistitems
	newcategoryadd.put()
	newresult = db.GqlQuery("Select * from Category where username = :1 and categoryname = :2",user,categ)
	newitems = []
	for result in newresult:
		newitems = result.items
	return render_template("deleteditems.html",user1=user,category=categ,newitemlist=newitems)
Exemplo n.º 3
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)
Exemplo n.º 4
0
def uploadxml():
	currentuser = users.get_current_user()
	nickname = currentuser.nickname()
	form = cgi.FieldStorage()
	#xmlfile = form["filename"]
	#data = "No data entered"
	fileitem = form['filename']

	# Test if the file was uploaded
	if fileitem.filename:
  		# strip leading path from file name to avoid 
  		# directory traversal attacks
   		fn = os.path.basename(fileitem.filename)
   		open('/tmp/' + fn, 'wb').write(fileitem.file.read())
   		message = 'The file "' + fn + '" was uploaded successfully'
   
	else:
   		message = 'No file was uploaded'
	message1=""
	xmldata = "<CATEGORY><NAME>Soccer Players</NAME><ITEM><NAME>Santi Cazorla</NAME></ITEM><ITEM><NAME>Robin Van Persie</NAME></ITEM><ITEM><NAME>Cesc Fabregas</NAME></ITEM><ITEM><NAME>Thierry Henry</NAME></ITEM></CATEGORY>"
	dom = parseString(xmldata)
	xmlTag = dom.getElementsByTagName('CATEGORY')
	if len(xmlTag)==0:
		message1 = "Category element not specified in Xml. Incorrect format"
		return render_template('xmlresult.html',fmessage=message1)
	#strip off the tag (<tag>data</tag>  --->   data):
	categNameElements = dom.getElementsByTagName('NAME')
	if len(categNameElements)==0:
		message1 = "Category name element not specified in the XML. Incorrect Format"
		return render_template('xmlresult.html',fmessage=message1)
	categNameEle = dom.getElementsByTagName('NAME')[0].toxml()
	categName = categNameEle.replace('<NAME>','').replace('</NAME>','')
	itemElements = dom.getElementsByTagName('ITEM')
	listitems=[]
	for itemElement in itemElements:
		itemE = itemElement.toxml()
		itemtag = itemE.replace('<ITEM>','').replace('</ITEM>','')
		itemname = itemtag.replace('<NAME>','').replace('</NAME>','')
		listitems.append(itemname)
	resultset = db.GqlQuery("Select * from Category where username = :1 and categoryname = :2",nickname,categName)
	if resultset.count()==0:
		newcategory=Category(username=nickname,categoryname=categName)
		newcategory.items = listitems
		newcategory.put()
		message1 = categName + " category created successfully"
		return render_template("xmlresult.html",fmessage=message1)
	else:
		message1 = "Category already exists"
		return render_template("xmlresult.html",fmessage=message1)
Exemplo n.º 5
0
def store():
	#resultset = db.GqlQuery("Select * from Category")
	#db.delete(resultset)
	currentuser = users.get_current_user()
	nickname = currentuser.nickname()
	form = cgi.FieldStorage()
	cnames = form.getvalue("categoryname")
	alreadyexists = db.GqlQuery("Select * from Category where username = :1 and categoryname = :2",nickname,cnames)
	if alreadyexists.count()>0:
		return render_template("categoryexists.html")
	else:
		itemnames = form.getvalue("items")
		itemlist = itemnames.split(",")
		newCategory = Category(username=nickname,categoryname=cnames)
		newCategory.items=itemlist
		newCategory.put()
		resultset = db.GqlQuery("Select * from Category")
		return render_template('Successfulnewcateg.html',results=cnames)
Exemplo n.º 6
0
def uploadXMLFile():
	form = cgi.FieldStorage();
	item = form["filename"];
	data = "";
	if item.file:
		data = item.file;
	try:
		doc = xml.dom.minidom.parse(data)
	except:
		message="Malformed XML Input"
		return render_template("xmlerror.html",error=message)
	items = doc.getElementsByTagName("NAME");
	itemtag = doc.getElementsByTagName("ITEM");
	if len(items) <= 1 or len(itemtag)!=len(items)-1:
		message="Category item missing or no items included in the XML"
		return render_template("xmlerror.html")
	owner = users.get_current_user().nickname()
	optionList = [];
	for node in items:
		optionList.append(node.firstChild.nodeValue);
	categoryName = optionList[0];
	existingcateg = db.GqlQuery("Select * from Category where username = :1 and categoryname = :2",owner,categoryName)
	if existingcateg.count()==0:
		optionList.remove(categoryName);
		newCategory = Category(username=owner,categoryname=categoryName);
		newCategory.items = optionList
		newCategory.put();
		return render_template('newxmlcateg.html',categ=categoryName,option=optionList);
	else:
		exitemset=[]
		rejitemset=[]
		for result in existingcateg:
			exitemset = result.items
		optionList.remove(categoryName)
		for item in exitemset:
			if item not in optionList:
				rejitemset.append(item)
		for item in rejitemset:
			deletedvotes = db.GqlQuery("Select * from Vote where username = :1 and categoryname = :2 and itemname = :3",owner,categoryName,item)
			db.delete(deletedvotes)
			deletecomments = db.GqlQuery("Select * from Comments where username = :1 and categoryname = :2 and itemname = :3",owner,categoryName,item)
			db.delete(deletecomments)
		editedcateg = Category(username=owner,categoryname=categoryName)
		editedcateg.items = optionList
		db.delete(existingcateg)
		editedcateg.put()
		return render_template("xmleditcateg.html",categname=categoryName,newlist=optionList,deletelist=rejitemset)
Exemplo n.º 7
0
def addnewitems():
	form = cgi.FieldStorage()
	user = form.getvalue("categowner")
	categ = form.getvalue("categchange")
	newitems = form.getvalue("addeditems")
	newitemlist = newitems.split(",")
	oldresultset = db.GqlQuery("Select * from Category where username = :1 and categoryname = :2",user,categ)
	olditemlist = []
	rejecteditems = []
	for result in oldresultset:
		olditemlist = result.items
	for item in newitemlist	:
		if item in olditemlist:
			rejecteditems.append(item)
		else:
			olditemlist.append(item)
	db.delete(oldresultset)
	newcategory = Category(username=user,categoryname=categ)
	newcategory.items = olditemlist
	newcategory.put()
	newresultset = db.GqlQuery("Select * from Category where username = :1 and categoryname = :2",user,categ)
	for result in newresultset:
		finalresult = result
	return render_template('changedcategory.html',user1=user,category=categ,old=olditemlist,rej=rejecteditems,fresult=finalresult)