Created
November 1, 2012 21:18
-
-
Save daGrevis/3996622 to your computer and use it in GitHub Desktop.
Calculates depth of comments w/ recursion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @staticmethod | |
| def calculate_depth(comments, comment=None, depth_level=1): | |
| """ | |
| @brief Calculates depth of comments w/ recursion. | |
| @param comments: Comments | |
| @param comment: Comment (for recursion, isn't used from outside) | |
| @param depth_level: Depth level (for recursion, isn't used from outside) | |
| @return Comments /w depth level | |
| """ | |
| for the_comment in comments: | |
| if the_comment.parent == comment: | |
| the_comment.depth_level = depth_level | |
| Comment.calculate_depth(comments, the_comment, depth_level + 1) | |
| return comments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment