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!")
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!")
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)
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)
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!")