def get_a_post(self, request): """Exposes an API endpoint to GET a Post to current user. """ logging.debug("KEY1:" + str(request.post_key)) key = ndb.Key(urlsafe=request.post_key) logging.debug("KEY2:" + str(key)) p = Post01.get_by_id(key.id()) logging.debug("p.TITLE:" + p.post_title) q_cmt = Comment01.query(Comment01.cmt_post == p.key).order(-Comment01.cmt_timestamp) clist = [] for c in q_cmt: clist.append( Comment( cmt_content=c.cmt_content, cmt_timestamp=c.cmt_timestamp ) ) pc = Post_Comments( post_title = p.post_title, post_content = p.post_content, post_timestamp = p.post_timestamp, post_author = p.post_author.email(), post_key = p.key.urlsafe(), comments = clist) # user = oauth.get_current_user(scope) logging.debug("post_key:" + p.key.urlsafe()) return pc
def get_all_post_titles(self, request): """Exposes an API endpoint to GET All Posts to current user. """ query = Post01.query().order(-Post01.post_timestamp) #user = endpoints.get_current_user(scope) user = endpoints.get_current_user() plist = [] for p in query: if user is None: raise endpoints.UnauthorizedException('unauthorized error') if p.post_author is None: email = "*****@*****.**" else: email = p.post_author.email() logging.debug("get_all_post_titles:email:" + email) plist.append( Post(post_title=p.post_title, post_timestamp=p.post_timestamp, post_key=p.key.urlsafe(), post_author=email)) # temporary # temporary # temporary #token_audience = oauth.get_client_id(scope) """ author_str = "email:"+user.email() + \ ", auth_domain:" + user.auth_domain() + \ ", user_id:" + str(user.user_id()) + \ ", nickname:" + user.nickname() + \ ", user:"******", client_id:" + token_audience plist.append(Post(post_author=author_str)) """ ALL_POSTS = PostCollection(items=plist) return ALL_POSTS
def get_my_post_titles(self, request): #user = oauth.get_current_user(scope) user = endpoints.get_current_user() query = Post01.query(Post01.post_author == user).order(-Post01.post_timestamp) plist = [] for p in query: if user is None: raise endpoints.UnauthorizedException('unauthorized error') plist.append( Post(post_title=p.post_title, post_timestamp=p.post_timestamp, post_key=p.key.urlsafe(), post_author=p.post_author.email())) ALL_POSTS = PostCollection(items=plist) return ALL_POSTS