fix: use 'keep_comments' parameter when editing text
authorraph
Mon, 26 Jul 2010 14:16:21 +0200
changeset 301 6e8fb4869d50
parent 300 7aaf5c0d6af4
child 302 55f97508300b
fix: use 'keep_comments' parameter when editing text
src/cm/tests/test_comment_positioning.py
src/cm/views/texts.py
--- a/src/cm/tests/test_comment_positioning.py	Thu Jul 22 17:27:24 2010 +0200
+++ b/src/cm/tests/test_comment_positioning.py	Mon Jul 26 14:16:21 2010 +0200
@@ -53,6 +53,23 @@
             else:
                 x, y , z, k = new
                 self.assert_comment(id, x, y, z, k) 
+
+    def test_remove_comment(self):
+        content     = u"""<html><body>This is a <b>test</b> text</body></html>"""
+        new_content = u"""<html><body>This is a <b>te</b>e<b>est</b> text</body></html>"""
+
+        text = Text.objects.create_text("text", "html", content, "", "", "", None)
+
+        comment1 = create_comment(2, 2, 2, 4)
+        comment2 = create_comment(2, 2, 2, 4)
+        
+        version = Text.objects.all()[0].get_latest_version()
+
+        self.assertEqual(len(version.get_comments()), 2)
+
+        version.edit("text", "html", new_content, keep_comments = False, cancel_modified_scopes=False)
+
+        self.assertEqual(len(version.get_comments()), 0)
             
     def test_wrapper_shifted(self):
         content     = u"""<html><body>This is a <b>test</b> text</body></html>"""
--- a/src/cm/views/texts.py	Thu Jul 22 17:27:24 2010 +0200
+++ b/src/cm/views/texts.py	Mon Jul 26 14:16:21 2010 +0200
@@ -666,9 +666,10 @@
         new_format = request.POST.get('format', text.last_text_version.format)
         new_note = request.POST.get('note',None)
         new_tags = request.POST.get('tags',None)
+        keep_comments = bool(request.POST.get('keep_comments',None))
         cancel_modified_scopes = (request.POST.get('cancel_modified_scopes',u'1') == u'1')
         version = text.get_latest_version()
-        version.edit(new_title, new_format, new_content, new_tags, new_note, True, cancel_modified_scopes)
+        version.edit(new_title, new_format, new_content, new_tags, new_note, keep_comments, cancel_modified_scopes)
 
         return version
 
@@ -681,8 +682,9 @@
         cancel_modified_scopes = (request.POST.get('cancel_modified_scopes',u'1') == u'1')
         
         new_text_version = text.edit(new_title, new_format, new_content, new_tags, new_note, keep_comments=True, cancel_modified_scopes=cancel_modified_scopes, new_version=True)
-        
-        new_text_version.edit(new_title, new_format, new_content, new_tags, new_note, True, cancel_modified_scopes)
+
+        keep_comments = bool(request.POST.get('keep_comments',None))
+        new_text_version.edit(new_title, new_format, new_content, new_tags, new_note, keep_comments, cancel_modified_scopes)
         new_text_version.user = request.user if request.user.is_authenticated() else None
         new_text_version.note = request.POST.get('note','')
         new_text_version.email = request.POST.get('email','')