def post(self): currentUser = user.getUserbyId(user.getLoggedInUser()) if not currentUser: self.error(403) self.response.out.write("not logged in") else: userMeta = json.loads(currentUser.metadata) if not userMeta["profile_completed"]: self.response.out.write("profile not completed") else: 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")) mytopic = Topic() mytopic.title = title mytopic.description = descrtiption mytopic.access_type = accessType mytopic.tags = tags owner = user.getUserbyId(user.getLoggedInUser()) mytopic.owner = owner.key() mytopic.is_deleted = False mytopic.put() self.redirect("/topics")
def post(self): currentUser = user.getUserbyId(user.getLoggedInUser()) if(not currentUser): self.error(403) self.response.out.write("not logged in") else : userMeta = json.loads(currentUser.metadata) if(not userMeta['profile_completed']): self.response.out.write("profile not completed") else: 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")) mytopic = Topic() mytopic.title = title mytopic.description = descrtiption mytopic.access_type = accessType mytopic.tags = tags owner = user.getUserbyId(user.getLoggedInUser()) mytopic.owner = owner.key() mytopic.is_deleted = False mytopic.put() self.redirect("/topics")
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): 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): currentUser = user.getUserbyId(user.getLoggedInUser()) if not currentUser: self.error(403) self.response.out.write("not logged in") else: userMeta = json.loads(currentUser.metadata) if not userMeta["profile_completed"]: self.redirect("/complete_profile") else: path = os.path.join(os.path.dirname(__file__), "../views", "add-topic.html") self.response.out.write(template.render(path, locals()))
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): currentUser = user.getUserbyId(user.getLoggedInUser()) if(not currentUser): self.error(403) self.response.out.write("not logged in") else: userMeta = json.loads(currentUser.metadata) if(not userMeta['profile_completed']): self.redirect("/complete_profile") else: path = os.path.join(os.path.dirname(__file__), '../views' , 'add-topic.html') self.response.out.write( template.render(path,locals()) )
def post(self): currentUser = user.getUserbyId(user.getLoggedInUser()) responseDict = {} if(not currentUser): responseDict['code'] = USER_NOT_LOGGEDIN_CODE responseDict['message'] = USER_NOT_LOGGED_IN_MSG self.response.out.write(json.dumps(responseDict)) else: commentText = self.request.get('comment') essayID = self.request.get('essay_id') userID = currentUser.id objEssay = Essay.get(essayID) commentsJSON = objEssay.comments commentDict = {} commentDict['comment_text'] = commentText commentDict['owner_id'] = userID commentDict['owner_name'] = currentUser.nickname commentDict['created'] = datetime.now().strftime("%b %d %Y %H:%M:%S") if not commentsJSON: finalJSON = {} commentsArray = [] commentsArray.append(commentDict) finalJSON['count'] = len(commentsArray) finalJSON['data'] = commentsArray objEssay.comments = json.dumps(finalJSON) objEssay.put() else: finalJSON = json.loads(commentsJSON) commentsArray = finalJSON['data'] commentsArray.append(commentDict) finalJSON['count'] = len(commentsArray) objEssay.comments = json.dumps(finalJSON) objEssay.put() commentDict['created'] = getTimeInDaysMinutesSeconds(getSecondsFromNow(datetime.now())) responseDict['comment_data'] = commentDict responseDict['code'] = SUCCESS_CODE responseDict['message'] = COMMENT_ADDED_MSG self.response.headers["Content-Type"] = "application/json" self.response.headers.add_header("Expires", "Thu, 01 Dec 1994 16:00:00 GMT") self.response.out.write(json.dumps(responseDict)) ################################################################################################### # End ADD COMMENT HANDLER ###################################################################################################
def post(self): ratingPoints = self.request.get('rate') essayID = self.request.get('idBox') currentUser = user.getUserbyId(user.getLoggedInUser()) responseDict = {} if(not currentUser): responseDict['code'] = USER_NOT_LOGGEDIN_CODE responseDict['message'] = USER_NOT_LOGGED_IN_MSG self.response.out.write(json.dumps(responseDict)) else: objEssay = Essay.get(essayID) ratingsJSON = objEssay.ratings if not self.hasRated(ratingsJSON,currentUser): currentRating = {} currentRating['rated_by'] = currentUser.id currentRating['rating_points'] = float(ratingPoints) time = datetime.now() currentRating['created'] = time.strftime("%b %d %Y %H:%M:%S") if not ratingsJSON: finalJSON = {} ratingsArray = [] ratingsArray.append(currentRating) finalJSON['data'] = ratingsArray finalJSON['count'] = len(ratingsArray) finalJSON['aggregate_rating'] = currentRating['rating_points'] objEssay.ratings = json.dumps(finalJSON) objEssay.put() else: finalJSON = json.loads(objEssay.ratings) ratingsArray = finalJSON['data'] ratingsArray.append(currentRating) finalJSON['data'] = ratingsArray finalJSON['count'] = len(ratingsArray) finalJSON['aggregate_rating'] = self.getAggregateRating(ratingsArray) objEssay.ratings = json.dumps(finalJSON) objEssay.put() responseDict['code'] = SUCCESS_CODE responseDict['message'] = RATING_SUCCESS_MSG self.response.out.write(json.dumps(responseDict)) else: responseDict['code'] = ALREADY_RATED_CODE responseDict['message'] = ALREADY_RATED_MSG self.response.out.write(json.dumps(responseDict))
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): logoutUrl = users.create_logout_url(self.request.uri) topics = Topic.all() topics.filter("access_type = ", 1) topics.filter("is_deleted = ", False) topicsArray = [] currentUser = user.getUserbyId(user.getLoggedInUser()) for topic in topics: topicDict = {} topicDict["id"] = topic.key() topicDict["title"] = topic.title topicDict["added_duration"] = library.helpers.getTimeInDaysMinutesSeconds( library.helpers.getSecondsFromNow(topic.created) ) topicDict["keywords"] = json.loads(topic.tags) topicDict["owner"] = topic.owner.nickname topicsArray.append(topicDict) if currentUser and topic.owner.id == currentUser.id: topicDict["is_owner"] = True path = os.path.join(os.path.dirname(__file__), "../views", "topics.html") self.response.out.write(template.render(path, locals()))
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): logoutUrl = users.create_logout_url(self.request.uri) topics = Topic.all() topics.filter('access_type = ', 1) topics.filter('is_deleted = ', False) topicsArray = [] currentUser = user.getUserbyId(user.getLoggedInUser()) for topic in topics: topicDict = {} topicDict['id'] = topic.key() topicDict['title'] = topic.title topicDict['added_duration'] = library.helpers.getTimeInDaysMinutesSeconds(library.helpers.getSecondsFromNow(topic.created)) topicDict['keywords'] = json.loads(topic.tags) topicDict['owner'] = topic.owner.nickname topicsArray.append(topicDict) if(currentUser and topic.owner.id == currentUser.id): topicDict['is_owner'] = True path = os.path.join(os.path.dirname(__file__), '../views' , 'topics.html') self.response.out.write( template.render(path,locals()) )
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()) )