Paginated Module Reference¶
paginated
is a utility module for offset pagination related functions.
Function Definition¶
compute_offset(page, items_per_page)
¶
Calculate the offset for pagination based on the given page number and items per page.
The offset represents the starting point in a dataset for the items on a given page. For example, if each page displays 10 items and you want to display page 3, the offset will be 20, meaning the display should start with the 21st item.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page |
int
|
The current page number. Page numbers should start from 1. |
required |
items_per_page |
int
|
The number of items to be displayed on each page. |
required |
Returns:
Type | Description |
---|---|
int
|
The calculated offset. |
Examples:
Source code in fastcrud/paginated/helper.py
paginated_response(crud_data, page, items_per_page)
¶
Create a paginated response based on the provided data and pagination parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
crud_data |
dict
|
Data to be paginated, including the list of items and total count. |
required |
page |
int
|
Current page number. |
required |
items_per_page |
int
|
Number of items per page. |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
A structured paginated response dict containing the list of items, total count, pagination flags, and numbers. |
Note
The function does not actually paginate the data but formats the response to indicate pagination metadata.