示例#1
0
 def delete_post(self, post_id):
     from app.posts.models import Post
     try:
         post = Post.get(Post.id == post_id)
         if self.owns_post(post):
             post.delete_instance()
             return "Done"
         return "You do not have correct permissions."
     except:
         return "Error"
示例#2
0
 def edit_post(self, post_id, content):
     from app.posts.models import Post
     try:
         post = Post.get(Post.id == post_id)
         if self.owns_post(post):
             post.content = content
             post.save()
             return "Done"
         return "Do not have correct permissions."
     except:
         return "Error"
示例#3
0
 def comment(self, post_id, comment_text):
     from app.posts.models import Post, Comment
     post = Post.get(Post.id == post_id)
     user = User.get(User.id == post.user)
     ids = [friend.id for friend in user.get_friends()]
     ids.append(user.id)
     print(ids)
     print(comment_text)
     try:
         if self.id in ids:
             Comment.create(
                 user=self,
                 post=post,
                 content=comment_text
             )
             return "Commented."
         return "You do not have correct permissions"
     except:
         return "Error commenting."