Falcon sorting helper
Project description
A small falcon hook to parse sorting elements from the request.
Usage
The easiest way to use this hook is the following:
@falcon.before(SortingHook())
def on_get(self, req, resp, user):
# Here req['context']['order'] is set
The Hook will look in the query parameters for parameters looking like sort=value
.
The default sorting order is ascending.
In order to sort in a descending order a minus (-
) sign needs to be specified before the value.
i.e. sort=-value
It is possible to specify multiple ordering values by separating them with a comma.
i.e. sort=-value1,value2
It will create a list in the request context accessible at req.context['order']
.
This list consists of tuples where the first element is the name of the field to sort on
and the second the order to follow (either ASC
or DESC
)
i.e. [('foo', 'ASC'), ('bar', 'DESC')]
.
Configuration options
One parameter can be passed to the hook:
sort_query_key : The name of the key used in the query to sort data. Default:
sort
.
Example:
@falcon.before(PaginationFromRequestHook(
sort_query_key='order',
))
def on_get(self, req, resp, user):
# Get request
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for falcon_sorting-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 958826c56b93e2e9e4bb42dc94feeb039c2e7130eb25ab57768deec07932a15f |
|
MD5 | 6df7adcc0ce1ca89c60a41da8a1da1d6 |
|
BLAKE2b-256 | 6a225c486d5677e1ae648a237ca40083ca91b2f1fecdc536d56201e6b9cae9ff |