marshmallow-code / marshmallow-code/flask-smorest
Optional pagination for view-endpoints
- Dominant language
- Python
- Stars
- 717
- Forks
- 77
- Avg merge
- 7h 49m
- Merged PRs (30d)
- 3
Description
At the moment, using `Blueprint.paginate()` on a view-endpoint will enforce pagination, even if no pagination parameters were passed by the client (`DEFAULT_PAGINATION_PARAMETERS`). Adding a parameter to make the pagination optional could cover some additional use-cases. In this case the PaginationParameters-object could be None instead of using the default values.
An example use-case would be an endpoint that is used to fill an HTML-table and is also accessed by another application that requires the whole data at once (e.g. to visualize the data).
Example behaviour:
```python
from flask.views import MethodView
from flask_smorest import Blueprint
bp = Blueprint("pets", "pets", description="pet related operations", url_prefix="/api/pets")
@bp.route("/")
class AllPets(MethodView):
"""route for operations on all pets"""
@bp.paginate(force=False)
def get(self, pagination_parameters, **kwargs):
"""get information on all pets"""
if pagination_parameters:
return Pet.objects.skip((pagination_parameters.page-1)*pagination_parameters.page_size).limit(page_size)
return Pet.objects
```
I think this behaviour could be archieved via small changes to PaginationMixin and _pagination_parameters_schema_factory.
Contributor guide
Research direction
Start with PaginationMixin and _pagination_parameters_schema_factory, the entry points named in the issue, and trace how DEFAULT_PAGINATION_PARAMETERS is applied by Blueprint.paginate(force=False). The change is done when omitted pagination parameters leave the PaginationParameters object as None while supplied parameters still paginate, matching the view-endpoint example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100