Пример #1
0
	def get(self):
		output = {}
		try:
			id_post_str = self.request.get("postId")
			id_post = int(id_post_str)
			self.response.headers['Content-Type'] = 'application/json'
			if(getPostByID(id_post)):
				output["answer"] = "find"
				output["title"] = getPostByID(id_post).title
				output["user"] = getPostByID(id_post).user.name
				output["recipe"] = getPostByID(id_post).recipe
				output["ingredients"] = getPostByID(id_post).ingredients
			else:
				output["answer"] = "not find"
			output["result"] = "ok"
			self.response.out.write(json.dumps(output))
		except:
			output["result"] = "error"
			self.response.out.write(json.dumps(output))
	def post(self):
		id_user = self.session.get("user_id")
		user = searchUserByID(id_user)

		if (user.admin is False):
			removeAllUsersFollowing(id_user)
			removeAllUsersFollowers(id_user)
			deleteYummysUser(id_user)
			deleteCommentsForUser(id_user)
			posts = getPostsByUser(id_user)
			for post in posts:
				id_post = post.key().id()
				if(getPostByID(id_post)):
					deleteCommentsForPost(id_post)
					deletePostYummys(id_post)
					deletePost(id_post)
			deleteCommentsForUser(id_user)
			deleteUser(id_user)
			self.redirect('/logout')
		else:
			id_user_str = self.request.get("profile_id_user")
			id_user = int(id_user_str)
			if(isUserFollowing(self.session.get("user_id"), id_user)):
				removeUserFollowing(self.session.get("user_id"), id_user)
			if(isUserFollowing(id_user, self.session.get("user_id"))):
				removeUserFollowing(id_user, self.session.get("user_id"))
			deleteYummysUser(id_user)
			deleteCommentsForUser(id_user)
			posts = getPostsByUser(id_user)
			for post in posts:
				id_post = post.key().id()
				if(getPostByID(id_post)):
					deleteCommentsForPost(id_post)
					deletePostYummys(id_post)
					deletePost(id_post)
			deleteUser(id_user)
			self.redirect('/feed')
	def get(self):
		output = {}
		try:
			id_post_str = self.request.get("postId")
			id_post = int(id_post_str)
			self.response.headers['Content-Type'] = 'application/json'
			if (getPostByID(id_post)):
				deleteCommentsForPost(id_post)
				deletePostYummys(id_post)
				if(deletePost(id_post)):
					output["answer"] = "valid"
				else:
					output["answer"] = "invalid"
				output["result"] = "ok"
				self.response.out.write(json.dumps(output))
			else:
				output["answer"] = "invalid"
				output["result"] = "error"
				self.response.out.write(json.dumps(output))
		except:
			output["result"] = "error"
			self.response.out.write(json.dumps(output))