django-sorter
django-sorter helps with sorting objects in Django templates without modifying your views, can be used multiple times on the same page or template, provides helpers to easily generate links and forms to switch the sorting criteria (including the sort order) and has ~100% test coverage.
Quickstart
Get the app with your favorte Python packaging tool, e.g.:
pip install django-sorter
List this application in the INSTALLED_APPS setting. Your settings file might look something like:
INSTALLED_APPS = ( # ... 'sorter', )If it’s not already added in your setup, add the request template context processor to the TEMPLATE_CONTEXT_PROCESSORS setting (you might need to add it):
TEMPLATE_CONTEXT_PROCESSORS = ( # ... 'django.core.context_processors.request', )Specify the allowed sorting criteria, for at least the default 'sort' sorting querystring parameter:
SORTER_ALLOWED_CRITERIA = { 'sort': ['first_name', 'creation_date', 'title'], }Add this line at the top of your template to load the sorting tags:
{% load sorter_tags %}Decide on a variable that you would like to sort, and use the sort tag on that variable before iterating over it.
{% sort objects as sorted_objects %}Optionally, you can display different sort links or forms:
<tr> <th>{% sortlink by "first_name" %}By first name{% endsortlink %}</th> <th>{% sortlink by "creation_date,-title" %}By creation date and title{% endsortlink %}</th> ... </tr>The template tag takes a comma separated list of sorting statements. It also is a block tag and allows you to set the label of the generated link. The previous snippet will be rendered like this:
<tr> <th><a href="/?sort=first_name" title="Sort by 'first_name' (asc)">By name</a></th> <th><a href="/?sort=creation_date,-title" title="Sort by 'creation_date' (asc) and 'title' (desc)">By creation and title</a></th> ... </tr>Similarly the {% sortform %} template tag renders a form instead of a simple link.
Metadata
Release files for django-sorter 0.2
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 | |
|---|---|---|---|---|
| django-sorter-0.2.tar.gz | 9.3 kB | Without provenance | Details |
Release files / django-sorter-0.2.tar.gz
| Download URL | django-sorter-0.2.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6863b881e2c8ebb5cb84eeae6cbf1d0902298d2bc15c14af24856b9935e4f4ef
|
|
BLAKE2b-256 checksum How to use checksums |
2e711bdd7a1793c4edbec038442d9561ca1740fde40172f56bb13c34f7cb1bd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-sorter 0.2
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.