def add_comment(cls, author, content, post_id, parent_id=-1): post = Post.get_by_id(post_id) if not post: raise Exception("no post %s" % post_id) parent_id = str(parent_id) post_id = str(post_id) dbcomment = DBComment.create(author=author, content=content, post_id=post.id, parent_id=parent_id) dbcomment.save() _ = dbcomment.stats # init stats post.stats.increase("comment_count") post.category.stats.increase("comment_count") return cls(dbcomment)
def get_by_id(cls, id): dbcomment = DBComment.get_by_id(id) return dbcomment and cls(dbcomment)