Giter Site home page Giter Site logo

django-sortable-listview's Introduction

Build Status Coverage Status

django-sortable-listview

An extension of django's ListView that provides sorting.

Features:

  • Works with django's built in pagination.
  • Contains templates & css for pagination and sort buttons (or just use the context_data and build your own).
  • Adds an arrow to show the sort direction on the active sort.
  • Knows what the next sort is (i.e. if you're already sorted by title in one direction, clicking on the title button/link again will sort it in the other direction).
  • Lets you specify default sort for your list (defaults to -id) and for each of the sortable fields.
  • Modifies the queryset, so your database does your sorting.
  • Maintains additional query strings (configurable)

Requirements

These are the supported versions. Older versions may also work.

* Python (2.7, 3.5, 3.6, 3.7)
* Django (1.11, 2.1, 2.2)

Install

Using pip::

pip install django-sortable-listview

If you want to use the provided templates and CSS add 'sortable_listview' to your INSTALLED_APPS in your django settings.

To see how to include the css and templates in your application, look at the example project. The css is just standard bootstrap.

Example Project

Screenshot of example project

To run the example project. First make sure django and django-sortable-listview are on your python path. For example, from inside a virtualenv::

pip install django
pip install django-sortable-listview

Then from your cloned folder::

cd example_project
python manage.py migrate
python manage.py runserver

You should be able to see the example project at localhost:8000. A database is provided with some sample content. The username and password is admin/admin

Development and Tests

For your development setup::

pip install -r requirements-dev.txt

To run the tests::

tox

You may not want to run the whole tox suite when you are doing development. In this case, uncomment the extra lines in requirements-dev.txt, but please don't commit these changes. (Suggestions welcome on a better way to manage this)

django-sortable-listview's People

Contributors

birdsarah avatar fle avatar janmalte avatar martinburchell avatar tooreht avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-sortable-listview's Issues

Please release .43

Hi could you please release .43. It is working great with my Django 3.0.2 project, but pip can't find a distribution that matches.

Thanks

remove encode('utf-8')

parse_qs(query_string.encode('utf-8'))

returns a dict with both keys and values are bytes.
This will work fine in Python 2. but in Python 3 bytes can not be compared to strings, and thus query parameters that supposed to be removed will be ignored except if you add the following line to the view:

del_query_parameters = [b'page', b'sort']

I think it is safe to remove encode('utf-8') and just use:

parse_qs(query_string)

Sorting over computed fiels

I would like be able to run sorting over model methods, annotated with

@property

Unfortunately, currently it seems that it is not supported.

please release new version

please release new version to reflect changes to master branch. Pip installs .41 as latest version.

Thanks

Encoding problem

 File "/home/taxiserver/taxienv/local/lib/python2.7/site-packages/sortable_listview/views.py", line 36, in get

  File "/home/taxiserver/taxienv/local/lib/python2.7/site-packages/sortable_listview/views.py", line 138, in get_sort_link_list

  File "/home/taxiserver/taxienv/local/lib/python2.7/site-packages/sortable_listview/views.py", line 149, in get_basic_sort_link

  File "/home/taxiserver/taxienv/local/lib/python2.7/site-packages/sortable_listview/views.py", line 69, in get_querystring
    def get_next_sort_string(self, field):

  File "/usr/lib/python2.7/urllib.py", line 1337, in urlencode
    l.append(k + '=' + quote_plus(str(elt)))

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

This shows up when we use version 0.30 and newer but not in 0.23. In query string we have also our parameters encoded which use Polish characters for example: "ąśćłó".

get_queryset support

Hi great package I like the minimalist CBV and Django-integrated pagination approach.

Unfortunately, the sorting is ignored when overriding get_queryset class method on SortableListViews. As in, it only works for CBV with queryset = ... field attributes.

AFAIK get_queryset is still the recommended approach for modifying a ListView qs based on request context variables. In my case, trying to sort paginated tables of model objects filtered by a user who's username is specified in the url.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.