Changeset View
Changeset View
Standalone View
Standalone View
comments/views/common.py
| Show All 26 Lines | def build_tree(comment: Comment) -> typed_templates.CommentTree: | ||||
| if comment.is_deleted: | if comment.is_deleted: | ||||
| return build_deleted_tree(comment) | return build_deleted_tree(comment) | ||||
| # FIXME(anna) remove when all comments have message_html | # FIXME(anna) remove when all comments have message_html | ||||
| comment.message_html = comment.message_html or markdown.render( | comment.message_html = comment.message_html or markdown.render( | ||||
| markdown.sanitize(comment.message) | markdown.sanitize(comment.message) | ||||
| ) | ) | ||||
| return typed_templates.CommentTree( | return typed_templates.CommentTree( | ||||
| id=comment.pk, | id=comment.pk, | ||||
| anchor=comment.anchor, | |||||
| full_name=comment.full_name, | full_name=comment.full_name, | ||||
| date=comment.date_created, | date=comment.date_created, | ||||
| message=assert_cast(str, comment.message), | message=assert_cast(str, comment.message), | ||||
| message_html=assert_cast(str, comment.message_html), | message_html=assert_cast(str, comment.message_html), | ||||
| like_url=comment.like_url, | like_url=comment.like_url, | ||||
| liked=assert_cast(bool, getattr(comment, 'liked')), | liked=assert_cast(bool, getattr(comment, 'liked')), | ||||
| likes=assert_cast(int, getattr(comment, 'number_of_likes')), | likes=assert_cast(int, getattr(comment, 'number_of_likes')), | ||||
| replies=[build_tree(reply) for reply in lookup.get(comment.pk, [])], | replies=[build_tree(reply) for reply in lookup.get(comment.pk, [])], | ||||
| Show All 23 Lines | def build_deleted_tree(comment: Comment) -> typed_templates.DeletedCommentTree: | ||||
| Prepare comments marked as deleted to be displayed in the comment tree. | Prepare comments marked as deleted to be displayed in the comment tree. | ||||
| Deleted comments with replies have to be kept in the database to preserve | Deleted comments with replies have to be kept in the database to preserve | ||||
| the integrity of the conversation, but their message and user should not | the integrity of the conversation, but their message and user should not | ||||
| be displayed. It should also be impossible to edit or delete them again. | be displayed. It should also be impossible to edit or delete them again. | ||||
| """ | """ | ||||
| return typed_templates.DeletedCommentTree( | return typed_templates.DeletedCommentTree( | ||||
| id=comment.pk, | id=comment.pk, | ||||
| anchor=comment.anchor, | |||||
| date=comment.date_created, | date=comment.date_created, | ||||
| replies=[build_tree(reply) for reply in lookup.get(comment.pk, [])], | replies=[build_tree(reply) for reply in lookup.get(comment.pk, [])], | ||||
| is_archived=comment.is_archived, | is_archived=comment.is_archived, | ||||
| is_top_level=True if comment.reply_to is None else False, | is_top_level=True if comment.reply_to is None else False, | ||||
| ) | ) | ||||
| return typed_templates.Comments( | return typed_templates.Comments( | ||||
| comment_url=comment_url, | comment_url=comment_url, | ||||
| Show All 24 Lines | |||||