11import calendar
22import datetime as dt
33import logging
4+ from zoneinfo import ZoneInfo
45
56# noinspection PyPep8Naming
67from bs4 import BeautifulSoup as bs
78from dateutil .parser import parse
8- from zoneinfo import ZoneInfo
99
1010from .category import Category
1111from .utils import (
@@ -1940,28 +1940,29 @@ def __str__(self):
19401940 def __repr__ (self ):
19411941 return 'Schedule resource: {}' .format (self .main_resource )
19421942
1943- def list_calendars (self , limit = None , * , query = None , order_by = None ):
1943+ def list_calendars (self , limit = None , * , query = None , order_by = None , batch = None ):
19441944 """ Gets a list of calendars
19451945
19461946 To use query an order_by check the OData specification here:
1947- http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/
1948- part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions
1949- -complete.html
1947+ https://docs.oasis-open.org/odata/odata/v4.0/errata03/os/odata-v4.0-errata03-os.html
19501948
19511949 :param int limit: max no. of calendars to get. Over 999 uses batch.
19521950 :param query: applies a OData filter to the request
19531951 :type query: Query or str
19541952 :param order_by: orders the result set based on this condition
19551953 :type order_by: Query or str
1954+ :param int batch: batch size, retrieves items in
1955+ batches allowing to retrieve more items than the limit.
19561956 :return: list of calendars
1957- :rtype: list[Calendar]
1957+ :rtype: list[Calendar] or Pagination
19581958
19591959 """
19601960 url = self .build_url (self ._endpoints .get ('root_calendars' ))
19611961
19621962 params = {}
1963- if limit :
1964- params ['$top' ] = limit
1963+ if limit is None or limit > self .protocol .max_top_value :
1964+ batch = self .protocol .max_top_value
1965+ params ['$top' ] = batch if batch else limit
19651966 if query :
19661967 params ['$filter' ] = str (query )
19671968 if order_by :
@@ -1974,10 +1975,16 @@ def list_calendars(self, limit=None, *, query=None, order_by=None):
19741975 data = response .json ()
19751976
19761977 # Everything received from cloud must be passed as self._cloud_data_key
1977- contacts = [self .calendar_constructor (parent = self , ** {
1978+ calendars = [self .calendar_constructor (parent = self , ** {
19781979 self ._cloud_data_key : x }) for x in data .get ('value' , [])]
1980+ next_link = data .get (NEXT_LINK_KEYWORD , None )
1981+ if batch and next_link :
1982+ return Pagination (parent = self , data = calendars ,
1983+ constructor = self .calendar_constructor ,
1984+ next_link = next_link , limit = limit )
1985+ else :
1986+ return calendars
19791987
1980- return contacts
19811988
19821989 def new_calendar (self , calendar_name ):
19831990 """ Creates a new calendar
0 commit comments