@@ -647,24 +647,80 @@ def get_all_pages_from_space(
647
647
content_type = "page" ,
648
648
):
649
649
"""
650
- Get all pages from space
650
+ Retrieve all pages from a Confluence space.
651
651
652
- :param space:
653
- :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
654
- :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
655
- fixed system limits. Default: 50
656
- :param status: OPTIONAL: list of statuses the content to be found is in.
657
- Defaults to current is not specified.
658
- If set to 'any', content in 'current' and 'trashed' status will be fetched.
659
- Does not support 'historical' status for now.
660
- :param expand: OPTIONAL: a comma separated list of properties to expand on the content.
661
- Default value: history,space,version.
662
- :param content_type: the content type to return. Default value: page. Valid values: page, blogpost.
663
- :return:
652
+ :param space: The space key to fetch pages from.
653
+ :param start: OPTIONAL: The starting point of the collection. Default: 0.
654
+ :param limit: OPTIONAL: The maximum number of pages per request. Default: 50.
655
+ :param status: OPTIONAL: Filter pages by status ('current', 'trashed', 'any'). Default: None.
656
+ :param expand: OPTIONAL: Comma-separated list of properties to expand. Default: history,space,version.
657
+ :param content_type: OPTIONAL: The content type to return ('page', 'blogpost'). Default: page.
658
+ :return: List containing all pages from the specified space.
664
659
"""
665
- return self .get_all_pages_from_space_raw (
666
- space = space , start = start , limit = limit , status = status , expand = expand , content_type = content_type
667
- ).get ("results" )
660
+ all_pages = [] # Initialize an empty list to store all pages
661
+ while True :
662
+ # Fetch a single batch of pages
663
+ response = self .get_all_pages_from_space_raw (
664
+ space = space ,
665
+ start = start ,
666
+ limit = limit ,
667
+ status = status ,
668
+ expand = expand ,
669
+ content_type = content_type ,
670
+ )
671
+
672
+ # Extract results from the response
673
+ results = response .get ("results" , [])
674
+ all_pages .extend (results ) # Add the current batch of pages to the list
675
+
676
+ # Break the loop if no more pages are available
677
+ if len (results ) < limit :
678
+ break
679
+
680
+ # Increment the start index for the next batch
681
+ start += limit
682
+ return all_pages
683
+
684
+ def get_all_pages_from_space_as_generator (
685
+ self ,
686
+ space ,
687
+ start = 0 ,
688
+ limit = 50 ,
689
+ status = None ,
690
+ expand = "history,space,version" ,
691
+ content_type = "page" ,
692
+ ):
693
+ """
694
+ Retrieve all pages from a Confluence space using pagination.
695
+
696
+ :param space: The space key to fetch pages from.
697
+ :param start: OPTIONAL: The starting point of the collection. Default: 0.
698
+ :param limit: OPTIONAL: The maximum number of pages per request. Default: 50.
699
+ :param status: OPTIONAL: Filter pages by status ('current', 'trashed', 'any'). Default: None.
700
+ :param expand: OPTIONAL: Comma-separated list of properties to expand. Default: history,space,version.
701
+ :param content_type: OPTIONAL: The content type to return ('page', 'blogpost'). Default: page.
702
+ :return: Generator yielding pages one by one.
703
+ """
704
+ while True :
705
+ # Fetch a single batch of pages
706
+ response = self .get_all_pages_from_space_raw (
707
+ space = space ,
708
+ start = start ,
709
+ limit = limit ,
710
+ status = status ,
711
+ expand = expand ,
712
+ content_type = content_type ,
713
+ )
714
+
715
+ # Extract results from the response
716
+ results = response .get ("results" , [])
717
+ yield from results # Yield each page individually
718
+
719
+ # Break the loop if no more pages are available
720
+ if len (results ) < limit :
721
+ break
722
+ start += limit
723
+ pass
668
724
669
725
def get_all_pages_from_space_trash (self , space , start = 0 , limit = 500 , status = "trashed" , content_type = "page" ):
670
726
"""
@@ -1238,7 +1294,7 @@ def remove_template(self, template_id):
1238
1294
def get_all_spaces (
1239
1295
self ,
1240
1296
start = 0 ,
1241
- limit = 500 ,
1297
+ limit = 50 ,
1242
1298
expand = None ,
1243
1299
space_type = None ,
1244
1300
space_status = None ,
0 commit comments