Fixes crash when editing imported text with orphan comment. 2.5.0
authorgibus
Thu, 31 Jan 2013 16:56:09 +0100
changeset 499 805e08ea57b1
parent 498 31d3fbe0c9a2
child 500 bd3d22f634f7
Fixes crash when editing imported text with orphan comment.
src/cm/views/create.py
--- a/src/cm/views/create.py	Thu Jan 31 14:54:54 2013 +0100
+++ b/src/cm/views/create.py	Thu Jan 31 16:56:09 2013 +0100
@@ -195,7 +195,9 @@
       # Process comments.
       if soup.co_ment_text.comments:
         comments_ids_map = {}
-        for imported_comment in soup.co_ment_text.comments.findAll('comment'):
+        all_comments = soup.co_ment_text.comments.findAll('comment')
+        # Sort by id in order to have parent processed before reply_to
+        for imported_comment in sorted(all_comments, key=lambda cid: cid.id.renderContents()):
           # Creates each comment.
           comment = Comment.objects.create(
               text_version=text.get_latest_version(),