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