Browse Source

refactor copy

Guénaël Muller 6 years ago
parent
commit
75aeb8e865
1 changed files with 4 additions and 12 deletions
  1. 4 12
      tracim/tracim/lib/content.py

+ 4 - 12
tracim/tracim/lib/content.py View File

865
         item: Content,
865
         item: Content,
866
         new_parent: Content=None,
866
         new_parent: Content=None,
867
         new_label: str=None,
867
         new_label: str=None,
868
+        do_save: bool=True,
868
         do_notify: bool=True,
869
         do_notify: bool=True,
869
     ) -> Content:
870
     ) -> Content:
870
         """
871
         """
891
         else:
892
         else:
892
             label = item.label
893
             label = item.label
893
 
894
 
894
-        # INFO - G.M - 15-03-2018 - Copy content with first_revision
895
-        # to have consistent content
896
         content = Content()
895
         content = Content()
897
-        cpy_rev = ContentRevisionRO.copy(item.first_revision, parent)
898
-        content.revisions.append(cpy_rev)
899
-        DBSession.add(content)
900
-
901
-        # INFO - G.M - 15-03-2018 - Add all older revision (history)
896
+        # INFO - G.M - 15-03-2018 - Add all revisions (history)
902
         for rev in item.revisions:
897
         for rev in item.revisions:
903
-            if rev == item.first_revision:
904
-                continue
905
             cpy_rev = ContentRevisionRO.copy(rev, parent)
898
             cpy_rev = ContentRevisionRO.copy(rev, parent)
906
             content.revisions.append(cpy_rev)
899
             content.revisions.append(cpy_rev)
907
-            DBSession.add(content)
908
 
900
 
909
         # INFO - GM - 15-03-2018 - add "copy" revision
901
         # INFO - GM - 15-03-2018 - add "copy" revision
910
         content.new_revision()
902
         content.new_revision()
916
             'content': item.id,
908
             'content': item.id,
917
             'revision': item.last_revision.revision_id,
909
             'revision': item.last_revision.revision_id,
918
         }
910
         }
919
-        DBSession.add(content)
920
-        self.save(content, ActionDescription.COPY, do_notify=do_notify)
911
+        if do_save:
912
+            self.save(content, ActionDescription.COPY, do_notify=do_notify)
921
         return content
913
         return content
922
 
914
 
923
     def copy_children(self, origin_content: Content, new_content: Content):
915
     def copy_children(self, origin_content: Content, new_content: Content):