@@ -83,6 +83,77 @@ Every openwisp module which has an API should use this class to configure
8383its own default settings, which will be merged with the settings of the
8484other modules.
8585
86+ ``openwisp_utils.api.pagination.OpenWispPagination ``
87+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88+
89+ A reusable pagination class for DRF views that provides consistent
90+ pagination behavior across OpenWISP modules with sensible defaults and
91+ flexible configuration.
92+
93+ **Default Behavior: **
94+
95+ - 10 items per page
96+ - Clients can request custom page sizes via ``?page_size=N `` query
97+ parameter
98+ - Maximum 100 items per page to prevent performance issues
99+ - Standard page navigation via ``?page=N ``
100+
101+ **Configuration via Django Settings: **
102+
103+ The following settings can be used to customize the default pagination
104+ behavior:
105+
106+ - ``OPENWISP_PAGINATION_PAGE_SIZE `` (default: ``10 ``): Default number of
107+ items per page
108+ - ``OPENWISP_PAGINATION_MAX_PAGE_SIZE `` (default: ``100 ``): Maximum
109+ allowed page size
110+ - ``OPENWISP_PAGINATION_PAGE_SIZE_QUERY_PARAM `` (default:
111+ ``"page_size" ``): Query parameter name for page size
112+
113+ **Usage in Views: **
114+
115+ .. code-block :: python
116+
117+ from openwisp_utils.api.pagination import OpenWispPagination
118+ from rest_framework.viewsets import ModelViewSet
119+
120+
121+ class DeviceViewSet (ModelViewSet ):
122+ queryset = Device.objects.all()
123+ serializer_class = DeviceSerializer
124+ pagination_class = OpenWispPagination
125+
126+ **Custom Configuration via Subclassing: **
127+
128+ For view-specific pagination requirements, you can subclass
129+ ``OpenWispPagination ``:
130+
131+ .. code-block :: python
132+
133+ from openwisp_utils.api.pagination import OpenWispPagination
134+
135+
136+ class LargePagination (OpenWispPagination ):
137+ page_size = 50
138+ max_page_size = 500
139+
140+
141+ class ReportViewSet (ModelViewSet ):
142+ queryset = Report.objects.all()
143+ serializer_class = ReportSerializer
144+ pagination_class = LargePagination
145+
146+ **Global Configuration: **
147+
148+ To use ``OpenWispPagination `` as the default pagination class for all DRF
149+ views in your project, add it to ``REST_FRAMEWORK `` settings:
150+
151+ .. code-block :: python
152+
153+ REST_FRAMEWORK = {
154+ " DEFAULT_PAGINATION_CLASS" : " openwisp_utils.api.pagination.OpenWispPagination" ,
155+ }
156+
86157 Storage Utilities
87158-----------------
88159
0 commit comments