def get(self): currentUser = user.getUserbyId(user.getLoggedInUser()) if not currentUser: self.response.out.write("not logged in") else: key = self.request.get("t") if not key: self.response.out.write("Arguments missing") else: topicKey = db.Key(key) topic = Topic.get(topicKey) if not topic: self.response.out.write("Invalid key") else: if not topic.owner.id == currentUser.id: self.response.out.write("You do not have the rights to delete this topic") else: topic.is_deleted = True metaData = {} time = datetime.now() metaData["delete_date"] = time.strftime("%b %d %Y %H:%M:%S") metaData["deleted_by"] = currentUser.nickname topic.deleteMetaData = json.dumps(metaData) topic.put() self.response.out.write("success")
def get(self): currentUser = user.getUserbyId(user.getLoggedInUser()) if(not currentUser): self.response.out.write("not logged in") else: key = self.request.get("t") if(not key): self.response.out.write("Arguments missing") else: topicKey = db.Key(key) topic = Topic.get(topicKey) if(not topic): self.response.out.write("Invalid key") else: if (not topic.owner.id == currentUser.id): self.response.out.write("You do not have the rights to delete this topic") else: topic.is_deleted = True metaData = {} time = datetime.now() metaData['delete_date'] = time.strftime("%b %d %Y %H:%M:%S") metaData['deleted_by'] = currentUser.nickname topic.deleteMetaData = json.dumps(metaData) topic.put() self.response.out.write('success')
def post(self): key = self.request.get("t") topic = Topic.get(key) currentUser = user.getUserbyId(user.getLoggedInUser()) if not currentUser: self.redirect('/login') else: myEssay = Essay() myEssay.essay_text = self.request.get("essay-text") myEssay.parent_topic = topic.key() myEssay.owner = currentUser.key() myEssay.put() self.redirect('/essays?t='+key)
def get(self): key = self.request.get("t") topic = Topic.get(key) if not topic: print "No Topic with this id found" self.error(500) else: topic_id = topic.key() current_user = users.get_current_user() if not current_user: self.redirect('/login') else: path = os.path.join(os.path.dirname(__file__), '../views' , 'new-essay.html') self.response.out.write( template.render(path,locals()) )
def post(self): try: key = self.request.get("t") if key: currentUser = user.getUserbyId(user.getLoggedInUser()) if not currentUser: print "not logged in" self.error(403) else: topicKey = db.Key(key) topic = Topic.get(topicKey) if not topic: print "Invalid key" self.error(500) else: modifierArray = [] if topic.owner.id == currentUser.id: tags = self.request.get_all("tags[]") tags = json.dumps(tags) title = self.request.get("title") descrtiption = self.request.get("description") accessType = int(self.request.get("access_type")) topic.title = title topic.description = descrtiption topic.access_type = accessType topic.tags = tags topicHistory = topic.history if topicHistory: topicHistoryArray = json.loads(topic.history) for myTopic in topicHistoryArray: modifierArray.append(myTopic) historyDict = {} historyDict["modifier"] = user.getLoggedInUser() time = datetime.now() historyDict["modified"] = time.strftime("%b %d %Y %H:%M:%S") modifierArray.append(historyDict) historyJson = json.dumps(modifierArray) topic.history = historyJson topic.put() self.redirect("/topics") else: print "Not the owner of the topic" self.error(403) else: self.error(500) except Exception: print Exception.message
def post(self): try: key = self.request.get("t") if(key): currentUser = user.getUserbyId(user.getLoggedInUser()) if(not currentUser): print "not logged in" self.error(403) else: topicKey = db.Key(key) topic = Topic.get(topicKey) if(not topic): print "Invalid key" self.error(500) else: modifierArray = [] if (topic.owner.id == currentUser.id): tags = (self.request.get_all("tags[]")) tags = json.dumps(tags) title = self.request.get('title') descrtiption = self.request.get("description") accessType = int(self.request.get("access_type")) topic.title = title topic.description = descrtiption topic.access_type = accessType topic.tags = tags topicHistory = topic.history if(topicHistory): topicHistoryArray = json.loads(topic.history) for myTopic in topicHistoryArray: modifierArray.append(myTopic) historyDict = {} historyDict['modifier'] = user.getLoggedInUser() time = datetime.now() historyDict['modified'] = time.strftime("%b %d %Y %H:%M:%S") modifierArray.append(historyDict) historyJson = json.dumps(modifierArray) topic.history = historyJson topic.put() self.redirect("/topics") else: print "Not the owner of the topic" self.error(403) else: self.error(500) except Exception: print Exception.message
def get(self): try: key = self.request.get("t") if key: topicKey = db.Key(key) topic = Topic.get(topicKey) tags = json.loads(topic.tags) currentUser = user.getLoggedInUser() if not currentUser: print "not logged in" self.error(403) elif topic.owner.id == currentUser: path = os.path.join(os.path.dirname(__file__), "../views", "edit-topic.html") self.response.out.write(template.render(path, locals())) else: print "Not the owner of the topic" self.error(403) else: self.error(500) except Exception: print Exception.message
def get(self): try: key = self.request.get("t") if(key): topicKey = db.Key(key) topic = Topic.get(topicKey) tags = json.loads(topic.tags) currentUser = user.getLoggedInUser() if(not currentUser): print "not logged in" self.error(403) elif (topic.owner.id == currentUser): path = os.path.join(os.path.dirname(__file__), '../views' , 'edit-topic.html') self.response.out.write( template.render(path,locals()) ) else: print "Not the owner of the topic" self.error(403) else: self.error(500) except Exception: print Exception.message
def get(self): key = self.request.get("t") topic = Topic.get(key) if not topic: print "No Topic with this id found" self.error(500) else: curentUser = user.getUserbyId(user.getLoggedInUser()) topic_id = topic.key() essaysArray = [] for essay in topic.topic: essayDict = {} essayDict['essay_text'] = essay.essay_text essayDict['owner_name'] = essay.owner.nickname essayDict['owner_id'] = essay.owner.id essayDict['essay_key'] = essay.key() essayDict['created'] = getTimeInDaysMinutesSeconds(getSecondsFromNow(essay.created)) if(essay.ratings): essayDict['ratings'] = json.loads(essay.ratings) essayDict['my_ratings'] = self.getMyRatings(essay.ratings, curentUser) else: essayDict['ratings'] ={'count':0,'aggregate_rating':0} essayDict['my_ratings'] = 0 if essay.comments: comments = json.loads(essay.comments) for comment in comments['data']: comment['created'] = getTimeInDaysMinutesSeconds(getSecondsFromNow(datetime.strptime((comment['created']),"%b %d %Y %H:%M:%S"))) essayDict['comments'] = comments else: essayDict['comments'] = "" essaysArray.append(essayDict) path = os.path.join(os.path.dirname(__file__), '../views' , 'essays.html') self.response.out.write( template.render(path,locals()) )