falcon-sorting-hook
A small falcon hook to parse sorting elements from the request.
Usage
The easiest way to use this hook is the following:
class Resource:
sorting_fields = ("foo", "bar") # List of fields allowed for sorting
@falcon.before(SortingHook())
def on_get(self, req, resp, user):
# Here req['context']['sort'] is set
The Hook will look in the query parameters for parameters looking like sort=value.
The default sorting order is ascending.
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 sorting 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['sort'].
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
Allowing fields for sorting
For security reasons, the fields allowed for sorting must be specified in
the sorting_fields attribute of the resource.
All the fields not defined in it will be discarded by the hook.
Default sorting order
It is possible to specify a default sorting order by setting the default_sorting attribute in the resource.
This attribute must be a string or a tuple that respects the convention we have for the request parameter.
The attributes specified as the default order must also be part of sorting_fields.
Examples:
default_sorting = '-foo'
# or
default_sorting = ('foo', '-bar')
Hook configuration
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
Metadata
Release files for falcon-sorting 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| falcon_sorting-0.2.0.tar.gz | 3.7 kB | Without provenance | Details for falcon_sorting-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| falcon_sorting-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for falcon_sorting-0.2.0-py3-none-any.whl |
Total release size: 8.3 kB
Release files / falcon_sorting-0.2.0.tar.gz
| Download URL | falcon_sorting-0.2.0.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d869fa5c8dfe6d34c694f71ad1116f7155899701ee67b36e9a16a09c49f2b980
|
|
BLAKE2b-256 checksum How to use checksums |
6308617d5d7eaaedb2fb2e52c3c153ff4714cbfdc8153de89f30b4626c0269c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.7
|
Release files / falcon_sorting-0.2.0-py3-none-any.whl
| Download URL | falcon_sorting-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c781efca49359ca0158d1106ec04198435a85c697b659143f321420eca05212d
|
|
BLAKE2b-256 checksum How to use checksums |
90bfaf89ac79e42d259fc75e9aa2a7dd4928845ff21098da5e11e895d46dffb3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.7
|
Security for falcon-sorting 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.