def comment_delete(self, comment): """Delete the comment with the entityKey """ if not comment.from_datastore: raise endpoints.NotFoundException("No comment for the given key") user = endpoints.get_current_user() if comment.from_user_key != main.get_user_key(user): return Comment(message="DO_NOT_HAVE_ACCESS") comment.key.delete() return Comment()
def sharepoint_insert(self, sharepoint): """ Update or insert a new Sharepoint """ if sharepoint.from_datastore: sharepoint_with_parent = sharepoint else: user = endpoints.get_current_user() sharepoint_with_parent = Sharepoint( user_key=main.get_user_key(user), detail=sharepoint.detail, title=sharepoint.title, user_nickname=user.nickname(), ) sharepoint_with_parent.put() return sharepoint_with_parent
def comment_insert(self, comment): """ Update or insert a new comment """ if comment.from_datastore: comment_with_parent = comment else: user = endpoints.get_current_user() comment_with_parent = Comment( sharepoint_key=comment.sharepoint_key, message=comment.message, from_user_key=main.get_user_key(user), from_user_nickname=user.nickname(), to_user_key=comment.to_user_key, to_user_nickname=comment.to_user_nickname, ) comment_with_parent.put() return comment_with_parent
def comment_list(self, query): """ list all the comments under certain Sharepoint and belongs to the current user """ user = endpoints.get_current_user() return query.filter( ndb.OR(Comment.from_user_key == main.get_user_key(user), Comment.to_user_key == main.get_user_key(user)) ).order(Comment.add_date, Comment.key)
def sharepoint_list(self, query): """ list all the sharepoints belonged to the current user """ user = endpoints.get_current_user() sharepoints = Sharepoint.query(Sharepoint.user_key == main.get_user_key(user)).order(-Sharepoint.add_date) return sharepoints