Browse Source

typing, comment, refactor for move_file method

Guénaël Muller 6 years ago
parent
commit
e30e03ba62
1 changed files with 18 additions and 7 deletions
  1. 18 7
      tracim/tracim/lib/webdav/sql_resources.py

+ 18 - 7
tracim/tracim/lib/webdav/sql_resources.py View File

964
         if invalid_path:
964
         if invalid_path:
965
             raise DAVError(HTTP_FORBIDDEN)
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
         workspace = self.content.workspace
981
         workspace = self.content.workspace
970
         parent = self.content.parent
982
         parent = self.content.parent
971
 
983
 
972
         with new_revision(self.content):
984
         with new_revision(self.content):
973
-            # Rename
985
+            # INFO - G.M - 2018-03-09 - First, renaming file if needed
974
             if basename(destpath) != self.getDisplayName():
986
             if basename(destpath) != self.getDisplayName():
975
                 new_given_file_name = transform_to_bdd(basename(destpath))
987
                 new_given_file_name = transform_to_bdd(basename(destpath))
976
                 new_file_name, new_file_extension = \
988
                 new_file_name, new_file_extension = \
983
                 self.content.file_extension = new_file_extension
995
                 self.content.file_extension = new_file_extension
984
                 self.content_api.save(self.content)
996
                 self.content_api.save(self.content)
985
 
997
 
986
-            # Move
998
+            # INFO - G.M - 2018-03-09 - Moving file if needed
987
             workspace_api = WorkspaceApi(self.user)
999
             workspace_api = WorkspaceApi(self.user)
988
             content_api = ContentApi(self.user)
1000
             content_api = ContentApi(self.user)
989
 
1001
 
996
                 content_api,
1008
                 content_api,
997
                 destination_workspace,
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
                 self.content_api.move(
1014
                 self.content_api.move(
1004
                     item=self.content,
1015
                     item=self.content,
1005
                     new_parent=destination_parent,
1016
                     new_parent=destination_parent,