Пример #1
0
	def post(self):
		username = self.get_secure_cookie("user")
		databaseOperations.connectToDatabase('astrodb')
		if not databaseOperations.isAdmin(username) or databaseOperations.isBanned(username) or not databaseOperations.isVerified(username):
			databaseOperations.closeConnectionToDatabase()
			self.redirect("/")		
			return
		title = self.get_argument("title", None)
		code_type = self.get_argument("codeType", None)
		description = self.get_argument("description", None)

		codeFile = self.request.files['codeFile'][0]
		path = "../code/" + str(databaseOperations.getNextCodeID())
		codePath = open(path, "w")
		codePath.write(codeFile['body'])
		
		databaseOperations.insertCode(title, code_type, description)

		userList = []
		userList.extend(databaseOperations.fetchAllUsers())#to convert from sqlite3 object to list
		msgs = []
		msgs.extend(databaseOperations.fetchMsgs(2))#to convert from sqlite3 object to list

		databaseOperations.closeConnectionToDatabase()
		
		#Get hits
		hitsList = hitsLib.readHits('hits.txt')
		hitsList = map(lambda x:x.split(':')[1], hitsList)
		
		self.render("../admin.html", userName=self.get_secure_cookie("user"), userList=userList, hitsList = hitsList, msgs=msgs, errMsg = "Code uploaded succesfully!")
Пример #2
0
	def get(self, content_id):
		databaseOperations.connectToDatabase('astrodb')
		
		if self.current_user:
			sessionUserID = databaseOperations.getIDFromUser(self.get_secure_cookie("user"))[0]
		else:
			sessionUserID = -1
		
		code=databaseOperations.fetchCode(content_id)
		if code:
			path = '../code/' + str(code[0])
			codeFile = open(path, 'r+')
			codeContent = codeFile.read()
			codeFile.close()
		else:
			codeContent = None
		
		self.render("../showcode.html", 
			userName=self.get_secure_cookie("user"),
			code=code, 
			codeContent = codeContent, 
			sessionUserID = sessionUserID,
			isAdmin=databaseOperations.isAdmin(self.get_secure_cookie("user")),
			commentNum=databaseOperations.fetchCommentNum(content_id), 
			comments=databaseOperations.fetchComments(content_id), 
			contentID=content_id)
		databaseOperations.closeConnectionToDatabase()
Пример #3
0
	def get(self, content_id):
		databaseOperations.connectToDatabase('astrodb')
		
		if self.current_user:
			sessionUserID = databaseOperations.getIDFromUser(self.get_secure_cookie("user"))[0]
		else:
			sessionUserID = -1
		
		news = databaseOperations.fetchNews(content_id)
		if news:
			path = '../news/' + str(news[0])
			newsFile = open(path, 'r+')
			newsContent = newsFile.read()
			newsFile.close()
		else:
			newsContent = None
		
		self.render("../shownews.html", 
			userName=self.get_secure_cookie("user"),
			news=news,
			newsContent = newsContent,
			sessionUserID = sessionUserID,
			isAdmin=databaseOperations.isAdmin(self.get_secure_cookie("user")),
			commentNum=databaseOperations.fetchCommentNum(content_id), 
			comments=databaseOperations.fetchComments(content_id), 
			contentID=content_id )
		databaseOperations.closeConnectionToDatabase()
Пример #4
0
	def post(self):
		username = self.get_secure_cookie("user")
		databaseOperations.connectToDatabase('astrodb')
		if not databaseOperations.isAdmin(username) or databaseOperations.isBanned(username) or not databaseOperations.isVerified(username):
			databaseOperations.closeConnectionToDatabase()
			self.redirect("/")
			return
		title = self.get_argument("title", None)
		date = time.strftime("%d %b %G %H:%M", time.localtime(time.time()))

		newsFile = self.request.files['newsFile'][0]
		path = "../news/" + str(databaseOperations.getNextNewsID())
		newsPath = open(path, "w")
		newsPath.write(newsFile['body'])
		
		newsimg = self.request.files['newsimg'][0]
		path = "../imgs/news/" + str(databaseOperations.getNextNewsID()) + ".jpg"
		imgPath = open(path, "w")
		imgPath.write(newsimg['body'])
		
		databaseOperations.insertNews(title, date)

		userList = []
		userList.extend(databaseOperations.fetchAllUsers())#to convert from sqlite3 object to list
		msgs = []
		msgs.extend(databaseOperations.fetchMsgs(2))#to convert from sqlite3 object to list

		databaseOperations.closeConnectionToDatabase()

		#Get hits
		hitsList = hitsLib.readHits('hits.txt')
		hitsList = map(lambda x:x.split(':')[1], hitsList)
		
		self.render("../admin.html", userName=self.get_secure_cookie("user"), userList=userList, hitsList = hitsList, msgs=msgs, errMsg = "News posted succesfully!")
Пример #5
0
	def post(self):
		try:
			unbannedUser = self.get_argument("unbannedUser")
			user = self.get_secure_cookie("user")
			databaseOperations.connectToDatabase('astrodb')
			if not databaseOperations.isAdmin(user):
				self.redirect("/")
				return
			databaseOperations.unban(unbannedUser)
			userList = []
			userList.extend(databaseOperations.fetchAllUsers())#to convert from sqlite3 object to list
			msgs = []
			msgs.extend(databaseOperations.fetchMsgs(2))#to convert from sqlite3 object to list
			
			#Get hits
			hitsList = hitsLib.readHits('hits.txt')
			hitsList = map(lambda x:x.split(':')[1], hitsList)
			
			self.render("../admin.html", userName=user, userList = userList, hitsList = hitsList, msgs=msgs, errMsg = "User " + unbannedUser + " succesfully unbanned")
			databaseOperations.closeConnectionToDatabase()
		except:
			userList = []
			userList.extend(databaseOperations.fetchAllUsers())#to convert from sqlite3 object to list
			msgs = []
			msgs.extend(databaseOperations.fetchMsgs(2))#to convert from sqlite3 object to list
			
			unbannedUser = self.get_argument("unbannedUser")
			self.render("../admin.html", userName=self.get_secure_cookie("user"), userList = userList, msgs=msgs, errMsg = "Error unbanning user " + unbannedUser)
Пример #6
0
	def get(self):
		databaseOperations.connectToDatabase('astrodb')
		news = []
		news.extend(databaseOperations.fetchAllNews(10))#to convert from sqlite3 object to list
		
		#counts the webpage hits
		hitsLib.updateHits('hits.txt')
                        
		#modifyList adds a preview of the news to every new(new[3])
		def modifyList(new):
			path = '../news/' + str(new[0])
			newFile = open(path, 'r+')
			newContent = newFile.read()
			newFile.close()
			finalNew = []
			finalNew.extend(x for x in new[:3])
			finalNew.append(newContent)
			finalNew.extend(x for x in new[3:])
			return finalNew
	
		news = map(modifyList, news)
		
		self.render("../main.html", 
			userName=self.get_secure_cookie("user"), 
			isAdmin=databaseOperations.isAdmin(self.get_secure_cookie("user")),
			news=news)
		databaseOperations.closeConnectionToDatabase()
Пример #7
0
	def get(self, content_id):
		databaseOperations.connectToDatabase('astrodb')
		
		if self.current_user:
			sessionUserID = databaseOperations.getIDFromUser(self.get_secure_cookie("user"))[0]
		else:
			sessionUserID = -1
		
		self.render("../showart.html", 
			userName=self.get_secure_cookie("user"),
			art=databaseOperations.fetchArt(content_id), 
			sessionUserID = sessionUserID,
			isAdmin=databaseOperations.isAdmin(self.get_secure_cookie("user")),
			commentNum=databaseOperations.fetchCommentNum(content_id), 
			comments=databaseOperations.fetchComments(content_id), 
			contentID=content_id)
		databaseOperations.closeConnectionToDatabase()
Пример #8
0
	def get(self):
		databaseOperations.connectToDatabase('astrodb')
		username = self.get_secure_cookie("user")
		if not databaseOperations.isAdmin(username) or databaseOperations.isBanned(username) or not databaseOperations.isVerified(username):
			databaseOperations.closeConnectionToDatabase()
			self.redirect("/")
			return
		else:
			#Get hits
			hitsList = hitsLib.readHits('hits.txt')
			hitsList = map(lambda x:x.split(':')[1], hitsList)
			userList = []
			userList.extend(databaseOperations.fetchAllUsers())#to convert from sqlite3 object to list
			msgs = []
			msgs.extend(databaseOperations.fetchMsgs(2))#to convert from sqlite3 object to list
			databaseOperations.closeConnectionToDatabase()
			self.render("../admin.html", userName=self.get_secure_cookie("user"), userList=userList, hitsList=hitsList, msgs=msgs, errMsg = None)
Пример #9
0
	def get(self, news_id):
		try:
			if not self.current_user:
				self.redirect("/login")
				return
			databaseOperations.connectToDatabase('astrodb')
			if not databaseOperations.isAdmin( self.get_secure_cookie("user") ):
				databaseOperations.closeConnectionToDatabase()
				self.redirect("/")
				return

			databaseOperations.deleteNews(news_id)
	
			databaseOperations.closeConnectionToDatabase()
			self.redirect("/")
			
		except:
			print "Error deleting news with news id", news_id
Пример #10
0
	def get(self, comment_id):
		try:
			if not self.current_user:
				self.redirect("/login")
				return
				
			databaseOperations.connectToDatabase('astrodb')
			
			content_id = databaseOperations.getContentIDFromCommentID(comment_id)[0]
			content_type = databaseOperations.getContentTypeFromID(content_id)[0]
			contentPath = "/show%s/%s" %(content_type, str(content_id))
			user = databaseOperations.getUserFromCommentID(comment_id)[0]

			if user == self.get_secure_cookie("user") or databaseOperations.isAdmin(self.get_secure_cookie("user")):
			#if user is the author of the comment, or if admin
				databaseOperations.deleteComment(comment_id)
	
			databaseOperations.closeConnectionToDatabase()
			self.redirect( contentPath )
			
		except:
			print "Error deleting comment with comment id", comment_id
Пример #11
0
	def post(self):
		username = self.get_secure_cookie("user")
		databaseOperations.connectToDatabase('astrodb')
		if not databaseOperations.isAdmin(username) or databaseOperations.isBanned(username) or not databaseOperations.isVerified(username):
			databaseOperations.closeConnectionToDatabase()
			self.redirect("/")		
			return
		description = self.get_argument("description", None)
		nextArtID = str(databaseOperations.getNextArtID())
		#upload gfx
		gfxFile = self.request.files['gfxFile'][0]
		path = "../imgs/art/gfx/" + nextArtID + ".jpg"
		gfxPath = open(path, "w")
		gfxPath.write(gfxFile['body'])
		
		#resize gfx and put in directory
		size = 250, 80
		bigImage = Image.open(path)
		try:
			bigImage.load()
		except:
			bigImage = bigImage.rotate(30)
		bigImage.save("../imgs/art/" + nextArtID + "small.jpg", "JPEG")
		
		#insert gfx into db
		databaseOperations.insertGfx(description)

		userList = []
		userList.extend(databaseOperations.fetchAllUsers())#to convert from sqlite3 object to list
		msgs = []
		msgs.extend(databaseOperations.fetchMsgs(2))#to convert from sqlite3 object to list

		databaseOperations.closeConnectionToDatabase()

		#Get hits
		hitsList = hitsLib.readHits('hits.txt')
		hitsList = map(lambda x:x.split(':')[1], hitsList)
			
		self.render("../admin.html", userName=self.get_secure_cookie("user"), userList=userList, hitsList = hitsList, msgs=msgs, errMsg = "GFX uploaded succesfully!")