@@ -56,57 +56,82 @@ def get_sharing_information(self):
56
56
"""Gets the sharing information for a folder."""
57
57
return self .list_item_all_fields .get_sharing_information ()
58
58
59
- def move_to (self , new_url , parent_folder = None ):
59
+ def move_to (self , destination ):
60
60
"""
61
- Moves the folder and its contents to a new folder at the specified URL .
61
+ Moves the folder and its contents under a new folder at the specified destination .
62
62
This method applies only to the context of a single site.
63
63
64
64
An exception is thrown if a folder with the same name as specified in the parameter already exists.
65
65
66
- :param str new_url: A string that specifies the URL for the new folder.
67
- :param Folder or None parent_folder: The existing parent folder where to move folder
66
+ :param str or Folder destination: Specifies the server relative url or an existing folder
67
+ where to move a folder.
68
68
"""
69
- if parent_folder is None :
70
- parent_folder = self .parent_folder
71
69
72
- return_type = Folder (self .context )
70
+ def _update_folder (url ):
71
+ self .set_property ("ServerRelativeUrl" , url )
73
72
74
- def _parent_folder_resolved ():
75
- new_path = SPResPath .create_relative (parent_folder .serverRelativeUrl , new_url )
76
- return_type .set_property ("ServerRelativeUrl" , str (new_path ))
77
- qry = ServiceOperationQuery (self , "MoveTo" , {"newUrl" : str (new_path )})
78
- self .context .add_query (qry )
73
+ def _move_to (destination_folder ):
74
+ """
75
+ :type destination_folder: Folder
76
+ """
77
+ destination_url = "/" .join ([destination_folder .serverRelativeUrl , self .name ])
78
+ qry = ServiceOperationQuery (self , "MoveTo" , {"newUrl" : destination_url })
79
+ self .context .add_query (qry ).after_query_execute (_update_folder , destination_url )
79
80
80
- parent_folder .ensure_property ("ServerRelativeUrl" , _parent_folder_resolved )
81
- return return_type
81
+ def _source_folder_resolved ():
82
+ if isinstance (destination , Folder ):
83
+ destination .ensure_property ("ServerRelativeUrl" , _move_to , destination )
84
+ else :
85
+ self .context .web .ensure_folder_path (destination ).after_execute (_move_to )
86
+
87
+ self .ensure_properties (["ServerRelativeUrl" , "Name" ], _source_folder_resolved )
88
+ return self
89
+
90
+ def move_to_using_path (self , destination ):
91
+ """
92
+ Moves the folder and its contents to a new folder at the specified path.
93
+ An exception is thrown if a folder with the same name as specified in the parameter already exists.
94
+
95
+ :param str or Folder destination: Specifies the server relative url or an existing folder
96
+ where to move a folder.
97
+ """
98
+
99
+ def _update_folder (url ):
100
+ self .set_property ("ServerRelativePath" , url )
101
+
102
+ def _move_to_using_path (destination_folder ):
103
+ """
104
+ :type destination_folder: Folder
105
+ """
106
+ destination_url = "/" .join ([str (destination_folder .server_relative_path ), self .name ])
107
+ qry = ServiceOperationQuery (self , "MoveToUsingPath" , {"DecodedUrl" : destination_url })
108
+ self .context .add_query (qry ).after_query_execute (_update_folder , destination_url )
82
109
83
- def move_to_with_parameters (self , new_relative_url , retain_editor_and_modified = False ):
84
- """Moves the folder with files to the destination URL.
110
+ def _source_folder_resolved ():
111
+ if isinstance (destination , Folder ):
112
+ destination .ensure_property ("ServerRelativePath" , _move_to_using_path , destination )
113
+ else :
114
+ self .context .web .ensure_folder_path (destination ).after_execute (_move_to_using_path )
115
+
116
+ self .ensure_properties (["ServerRelativePath" , "Name" ], _source_folder_resolved )
117
+ return self
118
+
119
+ def move_to_using_path_with_parameters (self , new_relative_path , retain_editor_and_modified = False ):
120
+ """Moves the folder with files to the destination Path.
85
121
86
- :type new_relative_url: str
87
- :type retain_editor_and_modified: bool
122
+ :param str new_relative_path: A full URL path that represents the destination folder.
123
+ :param bool retain_editor_and_modified:
88
124
"""
89
125
return_type = Folder (self .context )
90
- return_type .set_property ("ServerRelativeUrl " , new_relative_url )
126
+ return_type .set_property ("ServerRelativePath " , SPResPath ( new_relative_path ) )
91
127
92
128
def _move_folder ():
93
129
opt = MoveCopyOptions (retain_editor_and_modified_on_move = retain_editor_and_modified )
94
- MoveCopyUtil .move_folder (self .context , self .serverRelativeUrl , new_relative_url , opt )
130
+ MoveCopyUtil .move_folder_by_path (self .context , self .server_relative_path . DecodedUrl , new_relative_path , opt )
95
131
96
- self .ensure_property ("ServerRelativeUrl " , _move_folder )
132
+ self .ensure_property ("ServerRelativePath " , _move_folder )
97
133
return return_type
98
134
99
- def move_to_using_path (self , new_path ):
100
- """
101
- Moves the folder and its contents to a new folder at the specified path.
102
- An exception is thrown if a folder with the same name as specified in the parameter already exists.
103
-
104
- :param str new_path: Specifies the destination path.
105
- """
106
- qry = ServiceOperationQuery (self , "MoveToUsingPath" , SPResPath (new_path ))
107
- self .context .add_query (qry )
108
- return self
109
-
110
135
def share_link (self , link_kind , expiration = None ):
111
136
"""Creates a tokenized sharing link for a folder based on the specified parameters and optionally
112
137
sends an email to the people that are listed in the specified parameters.
@@ -252,66 +277,65 @@ def _loaded():
252
277
include_anonymous_links_in_notification ,
253
278
propagate_acl ,
254
279
return_type )
280
+
255
281
self .ensure_property ("ServerRelativePath" , _loaded )
256
282
return return_type
257
283
258
- def copy_to (self , new_relative_url , keep_both = False , reset_author_and_created = False , parent_folder = None ):
284
+ def copy_to (self , destination , keep_both = False , reset_author_and_created = False ):
259
285
"""Copies the folder with files to the destination URL.
260
286
261
- :param str new_relative_url: Folder name or server relative url
287
+ :param str or Folder destination: Parent folder object or server relative folder url
262
288
:param bool keep_both: bool
263
289
:param bool reset_author_and_created:
264
- :param Folder or None parent_folder: The existing parent folder
265
290
"""
266
- if parent_folder is None :
267
- parent_folder = self .parent_folder
268
291
return_type = Folder (self .context )
292
+ self .parent_collection .add_child (return_type )
269
293
270
- def _parent_folder_resolved ():
271
- new_path = SPResPath .create_relative (parent_folder .serverRelativeUrl , new_relative_url )
272
- return_type .set_property ("ServerRelativeUrl" , str (new_path ))
273
- self .ensure_property ("ServerRelativeUrl" , _copy_to , folder_path = new_path )
274
- parent_folder .ensure_property ("ServerRelativeUrl" , _parent_folder_resolved )
275
-
276
- def _copy_to (folder_path ):
294
+ def _copy_folder (destination_folder ):
295
+ """
296
+ :type destination_folder: Folder
297
+ """
298
+ destination_url = "/" .join ([destination_folder .serverRelativeUrl , self .name ])
299
+ return_type .set_property ("ServerRelativeUrl" , destination_url )
277
300
opts = MoveCopyOptions (keep_both = keep_both , reset_author_and_created_on_copy = reset_author_and_created )
278
- MoveCopyUtil .copy_folder (self .context , self .serverRelativeUrl , str (folder_path ), opts )
301
+ MoveCopyUtil .copy_folder (self .context , self .serverRelativeUrl , destination_url , opts )
302
+
303
+ def _source_folder_resolved ():
304
+ if isinstance (destination , Folder ):
305
+ destination .ensure_property ("ServerRelativeUrl" , _copy_folder , destination )
306
+ else :
307
+ self .context .web .ensure_folder_path (destination ).after_execute (_copy_folder )
279
308
309
+ self .ensure_property ("ServerRelativeUrl" , _source_folder_resolved )
280
310
return return_type
281
311
282
- def copy_to_using_path (self , new_relative_path , keep_both = False , reset_author_and_created = False ):
312
+ def copy_to_using_path (self , destination , keep_both = False , reset_author_and_created = False ):
283
313
"""Copies the folder with files to the destination Path.
284
314
285
- :type new_relative_path: str
315
+ :param str or Folder destination: Parent folder object or server relative folder url
286
316
:type keep_both: bool
287
317
:type reset_author_and_created: bool
288
318
"""
289
319
290
320
return_type = Folder (self .context )
291
- return_type . set_property ( "ServerRelativePath" , new_relative_path )
321
+ self . parent_collection . add_child ( return_type )
292
322
293
- def _copy_folder ():
323
+ def _copy_folder_by_path (destination_folder ):
324
+ """
325
+ :type destination_folder: Folder
326
+ """
327
+ destination_url = "/" .join ([str (destination_folder .server_relative_path ), self .name ])
328
+ return_type .set_property ("ServerRelativePath" , destination_url )
294
329
opts = MoveCopyOptions (keep_both = keep_both , reset_author_and_created_on_copy = reset_author_and_created )
295
- MoveCopyUtil .copy_folder_by_path (self .context , str (self .server_relative_path ), new_relative_path ,
296
- opts )
297
-
298
- self .ensure_property ("ServerRelativePath" , _copy_folder )
299
- return return_type
300
-
301
- def move_to_using_path_with_parameters (self , new_relative_path , retain_editor_and_modified = False ):
302
- """Moves the folder with files to the destination Path.
303
-
304
- :param str new_relative_path: A full URL path that represents the destination folder.
305
- :param bool retain_editor_and_modified:
306
- """
307
- return_type = Folder (self .context )
308
- return_type .set_property ("ServerRelativePath" , SPResPath (new_relative_path ))
330
+ MoveCopyUtil .copy_folder_by_path (self .context , str (self .server_relative_path ), destination_url , opts )
309
331
310
- def _move_folder ():
311
- opt = MoveCopyOptions (retain_editor_and_modified_on_move = retain_editor_and_modified )
312
- MoveCopyUtil .move_folder_by_path (self .context , self .server_relative_path .DecodedUrl , new_relative_path , opt )
332
+ def _source_folder_resolved ():
333
+ if isinstance (destination , Folder ):
334
+ destination .ensure_property ("ServerRelativePath" , _copy_folder_by_path , destination )
335
+ else :
336
+ self .context .web .ensure_folder_path (destination ).after_execute (_copy_folder_by_path )
313
337
314
- self .ensure_property ( "ServerRelativePath" , _move_folder )
338
+ self .ensure_properties ([ "ServerRelativePath" , "Name" ], _source_folder_resolved )
315
339
return return_type
316
340
317
341
@property
0 commit comments