Exemple #1
0
    def test_get_by_id_str(self):
        """get_by_id_str should return the correct comment."""
        james = UserEntity.register(username='******', password='******')

        a = BlogEntity.create_blog_entry(parent=blog_key(),
                                         title='a',
                                         article='content',
                                         created_by=james)

        c = CommentsEntity.comment_on_post(commentBy=james,
                                           commentOn=a,
                                           comment='abc')

        comment_id = str(c.key().id())
        self.assertEqual(type(CommentsEntity.get_by_id_str(comment_id)),
                         CommentsEntity,
                         msg=None)
Exemple #2
0
    def blog_comment(self, comment, blog_entry, comment_id, delete_comment,
                     redirect):
        """Handle blog comments."""

        comment_entry = CommentsEntity.get_by_id_str(comment_id)

        if comment_entry and blog_entry:
            if comment_entry.commentOn.key().id() == blog_entry.key().id():
                if comment_entry.commentBy.key().id() == self.user.key().id():
                    if delete_comment:
                        # Delete comment
                        comment_entry.delete()
                    else:
                        # Edit comment
                        comment_entry.edit_comment(comment, self.user)
                    self.render("/thanks.html", redirect=redirect)
        elif blog_entry:
            # New comment
            try:
                blog_entry.add_comment(commentBy=self.user, comment=comment)
                self.render("/thanks.html", redirect=redirect)
            except myExceptions.TooShort as e:
                self.redirect("/error?errorType=TooShort&errorMsg=", e)