1
1
from datetime import datetime
2
- from typing import TYPE_CHECKING
2
+ from typing import TYPE_CHECKING , Optional
3
+
4
+ from typing_extensions import Self
3
5
4
6
from office365 .runtime .client_result import ClientResult
5
7
from office365 .runtime .client_value_collection import ClientValueCollection
20
22
21
23
if TYPE_CHECKING :
22
24
from office365 .sharepoint .files .collection import FileCollection
25
+ from office365 .sharepoint .folders .collection import FolderCollection
23
26
24
27
25
28
class Folder (Entity ):
@@ -54,17 +57,14 @@ def download_folder(
54
57
def get_files (self , recursive = False ):
55
58
"""
56
59
Retrieves files
57
-
58
60
:param bool recursive: Determines whether to enumerate folders recursively
59
61
"""
60
62
from office365 .sharepoint .files .collection import FileCollection
61
63
62
64
return_type = FileCollection (self .context , self .files .resource_path , self )
63
65
64
66
def _loaded (parent ):
65
- """
66
- :type parent: Folder
67
- """
67
+ # type: ("Folder") -> None
68
68
[return_type .add_child (f ) for f in parent .files ]
69
69
if recursive :
70
70
for folder in parent .folders :
@@ -94,9 +94,7 @@ def _update_folder(url):
94
94
self .set_property ("ServerRelativeUrl" , url )
95
95
96
96
def _move_to (destination_folder ):
97
- """
98
- :type destination_folder: Folder
99
- """
97
+ # type: ("Folder") -> None
100
98
destination_url = "/" .join (
101
99
[destination_folder .serverRelativeUrl , self .name ]
102
100
)
@@ -261,10 +259,8 @@ def get_list_item_changes(self, query):
261
259
return return_type
262
260
263
261
def add (self , name ):
264
- """Adds the folder that is located under a current folder
265
-
266
- :type name: str
267
- """
262
+ # type: (str) -> Self
263
+ """Adds the folder that is located under a current folder"""
268
264
return self .folders .add (name )
269
265
270
266
def rename (self , name ):
@@ -352,6 +348,7 @@ def _loaded():
352
348
return return_type
353
349
354
350
def copy_to (self , destination , keep_both = False , reset_author_and_created = False ):
351
+ # type: (str|"Folder", bool, bool) -> "Folder"
355
352
"""Copies the folder with files to the destination URL.
356
353
357
354
:param str or Folder destination: Parent folder object or server relative folder url
@@ -362,9 +359,7 @@ def copy_to(self, destination, keep_both=False, reset_author_and_created=False):
362
359
self .parent_collection .add_child (return_type )
363
360
364
361
def _copy_folder (destination_folder ):
365
- """
366
- :type destination_folder: Folder
367
- """
362
+ # type: ("Folder") -> None
368
363
destination_url = "/" .join (
369
364
[destination_folder .serverRelativeUrl , self .name ]
370
365
)
@@ -393,6 +388,7 @@ def _source_folder_resolved():
393
388
def copy_to_using_path (
394
389
self , destination , keep_both = False , reset_author_and_created = False
395
390
):
391
+ # type: (str|"Folder", bool, bool) -> "Folder"
396
392
"""Copies the folder with files to the destination Path.
397
393
398
394
:param str or Folder destination: Parent folder object or server relative folder url
@@ -404,9 +400,7 @@ def copy_to_using_path(
404
400
self .parent_collection .add_child (return_type )
405
401
406
402
def _copy_folder_by_path (destination_folder ):
407
- """
408
- :type destination_folder: Folder
409
- """
403
+ # type: ("Folder") -> None
410
404
destination_url = "/" .join (
411
405
[str (destination_folder .server_relative_path ), self .name ]
412
406
)
@@ -425,9 +419,9 @@ def _source_folder_resolved():
425
419
"ServerRelativePath" , _copy_folder_by_path , destination
426
420
)
427
421
else :
428
- self .context .web .ensure_folder_path (destination ).after_execute (
429
- _copy_folder_by_path
430
- )
422
+ self .context .web .ensure_folder_path (destination ).get (). select (
423
+ [ "ServerRelativePath" ]
424
+ ). after_execute ( _copy_folder_by_path )
431
425
432
426
self .ensure_properties (["ServerRelativePath" , "Name" ], _source_folder_resolved )
433
427
return return_type
@@ -444,7 +438,8 @@ def storage_metrics(self):
444
438
445
439
@property
446
440
def list_item_all_fields (self ):
447
- """Specifies the list item fields (2) values for the list item corresponding to the folder."""
441
+ # type: () -> ListItem
442
+ """Specifies the list item fields values for the list item corresponding to the folder."""
448
443
return self .properties .get (
449
444
"ListItemAllFields" ,
450
445
ListItem (
@@ -467,6 +462,7 @@ def files(self):
467
462
468
463
@property
469
464
def folders (self ):
465
+ # type: () -> FolderCollection
470
466
"""Specifies the collection of list folders contained within the list folder."""
471
467
from office365 .sharepoint .folders .collection import FolderCollection
472
468
@@ -477,6 +473,7 @@ def folders(self):
477
473
478
474
@property
479
475
def parent_folder (self ):
476
+ # type: () -> "Folder"
480
477
"""Specifies the list folder."""
481
478
return self .properties .get (
482
479
"ParentFolder" ,
@@ -485,103 +482,85 @@ def parent_folder(self):
485
482
486
483
@property
487
484
def name (self ):
488
- """Specifies the list folder name.
489
-
490
- :rtype: str or None
491
- """
485
+ # type: () -> Optional[str]
486
+ """Specifies the list folder name."""
492
487
return self .properties .get ("Name" , None )
493
488
494
489
@property
495
490
def is_wopi_enabled (self ):
491
+ # type: () -> Optional[bool]
496
492
"""
497
493
Indicates whether the folder is enabled for WOPI default action.
498
-
499
- :rtype: bool or None
500
494
"""
501
495
return self .properties .get ("IsWOPIEnabled" , None )
502
496
503
497
@property
504
498
def prog_id (self ):
505
- """Gets the identifier (ID) of the application in which the folder was created.
506
-
507
- :rtype: str or None
508
- """
499
+ # type: () -> Optional[str]
500
+ """Gets the identifier (ID) of the application in which the folder was created."""
509
501
return self .properties .get ("ProgID" , None )
510
502
511
503
@property
512
504
def unique_id (self ):
513
- """Gets the unique ID of the folder.
514
-
515
- :rtype: str or None
516
- """
505
+ # type: () -> Optional[str]
506
+ """Gets the unique ID of the folder."""
517
507
return self .properties .get ("UniqueId" , None )
518
508
519
509
@property
520
510
def exists (self ):
521
- """Gets a Boolean value that indicates whether the folder exists.
522
-
523
- :rtype: bool or None
524
- """
511
+ # type: () -> Optional[bool]
512
+ """Gets a Boolean value that indicates whether the folder exists."""
525
513
return self .properties .get ("Exists" , None )
526
514
527
515
@property
528
516
def welcome_page (self ):
529
- """Specifies the server-relative URL for the list folder Welcome page.
530
-
531
- :rtype: str or None
532
- """
517
+ # type: () -> Optional[str]
518
+ """Specifies the server-relative URL for the list folder Welcome page."""
533
519
return self .properties .get ("WelcomePage" , None )
534
520
535
521
@property
536
522
def unique_content_type_order (self ):
537
- """Specifies the content type order for the list folder.
538
-
539
- :rtype: office365.sharepoint.contenttypes.content_type_id.ContentTypeId or None
540
- """
523
+ """Specifies the content type order for the list folder."""
541
524
return self .properties .get ("UniqueContentTypeOrder" , ContentTypeId ())
542
525
543
526
@property
544
527
def content_type_order (self ):
545
- """Specifies the content type order for the list folder.
546
-
547
- :rtype: office365.sharepoint.contenttypes.content_type_id.ContentTypeId or None
548
- """
528
+ """Specifies the content type order for the list folder."""
549
529
return self .properties .get ("ContentTypeOrder" , ContentTypeId ())
550
530
551
531
@property
552
532
def time_last_modified (self ):
553
- """Gets the last time this folder or a direct child was modified in UTC.
554
-
555
- :rtype: str or None
556
- """
557
- return self .properties .get ("TimeLastModified" , None )
533
+ # type: () -> Optional[datetime]
534
+ """Gets the last time this folder or a direct child was modified in UTC."""
535
+ return self .properties .get ("TimeLastModified" , datetime .min )
558
536
559
537
@property
560
538
def time_created (self ):
539
+ # type: () -> Optional[datetime]
561
540
"""
562
541
Gets when the folder was created in UTC.
563
- :rtype: datetime or None
564
542
"""
565
543
return self .properties .get ("TimeCreated" , datetime .min )
566
544
567
545
@property
568
546
def serverRelativeUrl (self ):
547
+ # type: () -> Optional[str]
569
548
"""
570
549
Gets the server-relative URL of the list folder.
571
- :rtype: str or None
572
550
"""
573
551
return self .properties .get ("ServerRelativeUrl" , None )
574
552
575
553
@property
576
554
def server_relative_path (self ):
555
+ # type: () -> Optional[SPResPath]
577
556
"""
578
557
Gets the server-relative Path of the list folder.
579
- :rtype: SPResPath or None
580
558
"""
581
559
return self .properties .get ("ServerRelativePath" , SPResPath ())
582
560
583
561
@property
584
562
def property_ref_name (self ):
563
+ # type: () -> str
585
564
return "ServerRelativeUrl"
586
565
587
566
def get_property (self , name , default_value = None ):
@@ -594,6 +573,7 @@ def get_property(self, name, default_value=None):
594
573
"ServerRelativePath" : self .server_relative_path ,
595
574
"StorageMetrics" : self .storage_metrics ,
596
575
"TimeCreated" : self .time_created ,
576
+ "TimeLastModified" : self .time_last_modified ,
597
577
}
598
578
default_value = property_mapping .get (name , None )
599
579
return super (Folder , self ).get_property (name , default_value )
0 commit comments