Преглед на файлове

Fix copy chidren by abandon of recursive strategy

Guénaël Muller преди 6 години
родител
ревизия
583704950e
променени са 2 файла, в които са добавени 8 реда и са изтрити 8 реда
  1. 6 6
      tracim/tracim/lib/content.py
  2. 2 2
      tracim/tracim/lib/webdav/sql_resources.py

+ 6 - 6
tracim/tracim/lib/content.py Целия файл

@@ -866,7 +866,7 @@ class ContentApi(object):
866 866
         new_parent: Content=None,
867 867
         new_label: str=None,
868 868
         do_notify: bool=True,
869
-    ) -> None:
869
+    ) -> Content:
870 870
         if (not new_parent and not new_label) or (new_parent == item.parent and new_label == item.label):  # nopep8
871 871
             # TODO - G.M - 08-03-2018 - Use something else than value error
872 872
             raise ValueError("You can't copy file into itself")
@@ -897,11 +897,6 @@ class ContentApi(object):
897 897
             content.revisions.append(cpy_rev)
898 898
             DBSession.add(content)
899 899
 
900
-        # TODO - G.M - 15-03-2018 - Child copy broken !
901
-        # INFO - G.M - 15-03-2018 - copy childrens (comments and others things)
902
-        # for child in item.children:
903
-        #    self.copy(child, content)
904
-
905 900
         # INFO - GM - 15-03-2018 - add "copy" revision
906 901
         content.new_revision()
907 902
         content.parent = parent
@@ -914,6 +909,11 @@ class ContentApi(object):
914 909
         }
915 910
         DBSession.add(content)
916 911
         self.save(content, ActionDescription.COPY, do_notify=do_notify)
912
+        return content
913
+
914
+    def copy_children(self, origin_content:Content, new_content: Content):
915
+        for child in origin_content.children:
916
+            self.copy(child, new_content)
917 917
 
918 918
     def move_recursively(self, item: Content,
919 919
                          new_parent: Content, new_workspace: Workspace):

+ 2 - 2
tracim/tracim/lib/webdav/sql_resources.py Целия файл

@@ -1039,12 +1039,12 @@ class File(DAVNonCollection):
1039 1039
         )
1040 1040
         workspace = self.content.workspace
1041 1041
         parent = self.content.parent
1042
-        self.content_api.copy(
1042
+        new_content = self.content_api.copy(
1043 1043
             item=self.content,
1044 1044
             new_label=new_file_name,
1045 1045
             new_parent=destination_parent,
1046 1046
         )
1047
-
1047
+        self.content_api.copy_children(self.content, new_content)
1048 1048
         transaction.commit()
1049 1049
 
1050 1050
     def supportRecursiveMove(self, destPath):