Exemplo n.º 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)
		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!")
Exemplo n.º 2
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!")
Exemplo n.º 3
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)
Exemplo n.º 4
0
	def post(self, content_id):
		username = self.get_secure_cookie("user")
		databaseOperations.connectToDatabase('astrodb')
		if not self.current_user or databaseOperations.isBanned(username) or not databaseOperations.isVerified(username):
			self.redirect("/login")
			return
		(comment, user) = (self.get_argument("comment", None), self.current_user)
		date = time.strftime("%d %b %G %H:%M", time.localtime(time.time()))
		user_id = databaseOperations.getIDFromUser(user)[0]
		content_type = databaseOperations.getContentTypeFromID(content_id)[0]
		print content_type
		
		if not comment:
			self.redirect( "/show%s/%s" %(content_type, str(content_id)) )
			return
			
		databaseOperations.insertComment(content_id, user_id, comment, date)
		databaseOperations.closeConnectionToDatabase()
		self.redirect( "/show%s/%s" %(content_type, str(content_id)) )
Exemplo n.º 5
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!")