Ver código fonte

typing, comment, refactor for move_file method

Guénaël Muller 6 anos atrás
pai
commit
e30e03ba62
1 arquivos alterados com 18 adições e 7 exclusões
  1. 18 7
      tracim/tracim/lib/webdav/sql_resources.py

+ 18 - 7
tracim/tracim/lib/webdav/sql_resources.py Ver arquivo

@@ -964,13 +964,25 @@ class File(DAVNonCollection):
964 964
         if invalid_path:
965 965
             raise DAVError(HTTP_FORBIDDEN)
966 966
 
967
-    def move_file(self, destpath):
967
+    def move_file(self, destpath: str) -> None:
968
+        """
969
+        Move file mean changing the path to access to a file. This can mean
970
+        simple renaming(1), moving file from a directory to one another(2)
971
+        but also renaming + moving file from a directory to one another at
972
+        the same time (3).
973
+
974
+        (1): move /dir1/file1 -> /dir1/file2
975
+        (2): move /dir1/file1 -> /dir2/file1
976
+        (3): move /dir1/file1 -> /dir2/file2
977
+        :param destpath: destination path of webdav move
978
+        :return: nothing
979
+        """
968 980
 
969 981
         workspace = self.content.workspace
970 982
         parent = self.content.parent
971 983
 
972 984
         with new_revision(self.content):
973
-            # Rename
985
+            # INFO - G.M - 2018-03-09 - First, renaming file if needed
974 986
             if basename(destpath) != self.getDisplayName():
975 987
                 new_given_file_name = transform_to_bdd(basename(destpath))
976 988
                 new_file_name, new_file_extension = \
@@ -983,7 +995,7 @@ class File(DAVNonCollection):
983 995
                 self.content.file_extension = new_file_extension
984 996
                 self.content_api.save(self.content)
985 997
 
986
-            # Move
998
+            # INFO - G.M - 2018-03-09 - Moving file if needed
987 999
             workspace_api = WorkspaceApi(self.user)
988 1000
             content_api = ContentApi(self.user)
989 1001
 
@@ -996,10 +1008,9 @@ class File(DAVNonCollection):
996 1008
                 content_api,
997 1009
                 destination_workspace,
998 1010
             )
999
-            if destination_parent == parent and destination_workspace == workspace:  # nopep8
1000
-                # Do not move to same place
1001
-                pass
1002
-            else:
1011
+            if destination_parent != parent or destination_workspace != workspace:  # nopep8
1012
+                #  INFO - G.M - 12-03-2018 - Avoid moving the file "at the same place"  # nopep8
1013
+                #  if the request does not result in a real move.
1003 1014
                 self.content_api.move(
1004 1015
                     item=self.content,
1005 1016
                     new_parent=destination_parent,