Skip to content

Commit

Permalink
Merge pull request #20 from djk2/support_bootstrap5
Browse files Browse the repository at this point in the history
Version v2.0.0, refere to issue #18 and #19
  • Loading branch information
djk2 authored Apr 1, 2021
2 parents 5f4d2a4 + ba43fe3 commit 047c698
Show file tree
Hide file tree
Showing 29 changed files with 16,604 additions and 243 deletions.
139 changes: 78 additions & 61 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,85 @@
sudo: false
language: python
matrix:
include:
- python: '3.6'
env: TOXENV=py36-djmaster-dtmaster-tests
- python: '3.6'
env: TOXENV=py36-djmaster-dt1.21-tests
- python: '3.6'
env: TOXENV=py36-djmaster-dt2.0-tests
- python: '3.6'
env: TOXENV=py36-dj2.0-dtmaster-tests
- python: '3.6'
env: TOXENV=py36-dj2.1-dtmaster-tests
- python: '3.6'
env: TOXENV=py36-dj2.0-dt1.21-tests
- python: '3.6'
env: TOXENV=py36-dj2.0-dt2.0-tests
- python: '3.6'
env: TOXENV=py36-dj2.1-dt1.21-tests
- python: '3.6'
env: TOXENV=py36-dj2.1-dt2.0-tests
- python: '2.7'
env: TOXENV=py27-dj1.11-dt1.7-tests
- python: '2.7'
env: TOXENV=py27-dj1.11-dt1.21-tests
- python: '3.6'
env: TOXENV=py36-dj1.11-dt1.7-tests
- python: '3.6'
env: TOXENV=py36-dj1.11-dt1.21-tests
- python: '2.7'
env: TOXENV=py27-dj1.9-dt1.5-tests
- python: '2.7'
env: TOXENV=py27-dj1.9-dt1.6-tests
- python: '2.7'
env: TOXENV=py27-dj1.10-dt1.5-tests
- python: '2.7'
env: TOXENV=py27-dj1.10-dt1.6-tests
- python: '3.6'
env: TOXENV=py36-dj1.9-dt1.5-tests
- python: '3.6'
env: TOXENV=py36-dj1.9-dt1.6-tests
- python: '3.6'
env: TOXENV=py36-dj1.10-dt1.5-tests
- python: '3.6'
env: TOXENV=py36-dj1.10-dt1.6-tests
- python: '2.7'
env: TOXENV=py27-flake
- python: '3.6'
env: TOXENV=py36-flake

allow_failures:
- python: '3.6'
env: TOXENV=py36-djmaster-dtmaster-tests
- python: '3.6'
env: TOXENV=py36-djmaster-dt1.21-tests
- python: '3.6'
env: TOXENV=py36-djmaster-dt2.0-tests
- python: '3.6'
env: TOXENV=py36-dj2.0-dtmaster-tests
- python: '3.6'
env: TOXENV=py36-dj2.1-dtmaster-tests
include:
- python: '3.8'
env: TOXENV=py38-djmaster-dtmaster-tests
- python: '3.8'
env: TOXENV=py38-dj3.0-dt2.3-tests
- python: '3.8'
env: TOXENV=py38-dj3.0-dtmaster-tests
- python: '3.8'
env: TOXENV=py38-dj3.1-dt2.3-tests
- python: '3.8'
env: TOXENV=py38-dj3.1-dtmaster-tests
- python: '3.6'
env: TOXENV=py36-dj2.0-dt1.19-tests
- python: '3.6'
env: TOXENV=py36-dj2.0-dt1.21-tests
- python: '3.6'
env: TOXENV=py36-dj2.0-dt2.0-tests
- python: '3.6'
env: TOXENV=py36-dj2.0-dt2.1-tests
- python: '3.6'
env: TOXENV=py36-dj2.0-dt2.2-tests
- python: '3.6'
env: TOXENV=py36-dj2.1-dt1.19-tests
- python: '3.6'
env: TOXENV=py36-dj2.1-dt1.21-tests
- python: '3.6'
env: TOXENV=py36-dj2.1-dt2.0-tests
- python: '3.6'
env: TOXENV=py36-dj2.1-dt2.1-tests
- python: '3.6'
env: TOXENV=py36-dj2.1-dt2.2-tests
- python: '2.7'
env: TOXENV=py27-dj1.11-dt1.19-tests
- python: '2.7'
env: TOXENV=py27-dj1.11-dt1.21-tests
- python: '3.6'
env: TOXENV=py36-dj1.11-dt1.19-tests
- python: '3.6'
env: TOXENV=py36-dj1.11-dt1.21-tests
- python: '2.7'
env: TOXENV=py27-dj1.9-dt1.15-tests
- python: '2.7'
env: TOXENV=py27-dj1.9-dt1.16-tests
- python: '2.7'
env: TOXENV=py27-dj1.10-dt1.15-tests
- python: '2.7'
env: TOXENV=py27-dj1.10-dt1.16-tests
- python: '2.7'
env: TOXENV=py27-dj1.11-dt1.15-tests
- python: '2.7'
env: TOXENV=py27-dj1.11-dt1.16-tests
- python: '3.6'
env: TOXENV=py36-dj1.9-dt1.15-tests
- python: '3.6'
env: TOXENV=py36-dj1.9-dt1.16-tests
- python: '3.6'
env: TOXENV=py36-dj1.10-dt1.15-tests
- python: '3.6'
env: TOXENV=py36-dj1.10-dt1.16-tests
- python: '3.6'
env: TOXENV=py36-dj1.11-dt1.15-tests
- python: '3.6'
env: TOXENV=py36-dj1.11-dt1.16-tests
- python: '2.7'
env: TOXENV=py27-flake
- python: '3.6'
env: TOXENV=py36-flake
- python: '3.6'
env: TOXENV=py36-isort

allow_failures:
- python: '3.8'
env: TOXENV=py38-djmaster-dtmaster-tests
- python: '3.8'
env: TOXENV=py38-dj3.0-dtmaster-tests
- python: '3.8'
env: TOXENV=py38-dj3.1-dtmaster-tests

install:
- pip install tox>=3.1.2
- pip install tox>=3.23.0
script:
- tox
- tox
17 changes: 15 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
CHANGELOG
===========

v. 2.0.0
--------

* Support for Django 3.1
* Tests with django-tables2 v2.3
* Add support for Bootstrap5
* Add special classes `ColumnShiftTableBootstrap3`,
`ColumnShiftTableBootstrap4` and `ColumnShiftTableBootstrap5`
* Change default inherit for django_tables2_column_shifter/templtes/table.html
from `django_tables2_column_shifter/bootstrap.html` to `django_tables2_column_shifter/bootstrap4.html`
so class `ColumnShiftTable` by default call bootstrap4 template from django-tables2.
**If you use different bootstrap version then 4 please use one of class: ColumnShiftTableBootstrap2/3/4/5 **
v. 0.5.2
--------
* Add locale Brazilian Portuguese

* Add locale Brazilian Portuguese

v. 0.5.1
--------
Expand Down
107 changes: 81 additions & 26 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,38 @@ django-tables2-column-shifter
About the app:
Simple extension for django-tables2 to dynamically show or hide columns using jQuery.
Application uses web storage to store information whih columns are visible or not.
Using JQuery, Bootstrap3 or Bootstrap4 and Django >=1.9.
Using JQuery, Bootstrap3 or Bootstrap4 or Bootstrap5 and Django >=1.9.

- Tested by tox with:

* Python :2.7, 3.6
* Django : 1.9, 1.10, 1.11, 2.0, 2.1, master
* django-tables2 : 1.5, 1.6, ..., 1.21, 2.0, master
**Warning** : - Since version 2.0 my extension works by default with bootstrap4.
I highly recommend to inherit explicite from tables class indicate on bootstrap version.
I.e if you use in your project bootstrap in version 5. Your `Tables` classes should inherit from
` django_tables2_column_shifter.tables.ColumnShiftTableBootstrap5`.
Now you should inherit from:
* bootstrap2 - ColumnShiftTableBootstrap2,
* bootstrap3 - ColumnShiftTableBootstrap3,
* bootstrap4 - ColumnShiftTableBootstrap4,
* bootstrap5 - ColumnShiftTableBootstrap5,

- Supported:
### Tested by tox with:

* Django >= 1.9
* django-tables2 >= 1.5.0 (earlier version probably will be work but wasn't tested)
* **bootstrap2** / **bootstrap3** / **bootstrap4** / **bootstrap4.1.3**
* **JQuery**
* Python :2.7, 3.6, 3.7, 3.8
* Django : 1.9, 1.10, 1.11, 2.0, 2.1, 3.0, 3.1, master
* django-tables2 : 1.5, 1.6, ..., 1.21, 2.0, 2.1, 2.2, 2.3, master

- Supported locale:
### Supported:

* EN - (English)
* PL - (Polish)
* EL - (Greek / Hellenic Republic)
* PT-BR - (Portuguese - Brazilian)
* Django >= 1.9
* django-tables2 >= 1.5.0 (earlier version probably will be work but wasn't tested)
* **bootstrap2** / **bootstrap3** / **bootstrap4** / **bootstrap4.1.3** / **bootstrap5 beta3**
* **JQuery**

### Supported locale:

* EN - (English)
* PL - (Polish)
* EL - (Greek / Hellenic Republic)
* PT-BR - (Portuguese - Brazilian)


More information about django-tables in here: https://django-tables2.readthedocs.io/
Expand Down Expand Up @@ -118,17 +129,32 @@ To use app, you must inherit your table class from ``django_tables2_column_shift
first_name = models.CharField("First name", max_length=50)
last_name = models.CharField("Last name", max_length=50)

tables.py - change inherit to ColumnShiftTable::
tables.py - change inherit to: ColumnShiftTableBootstrap2 or ColumnShiftTableBootstrap3,
ColumnShiftTableBootstrap4, ColumnShiftTableBootstrap5::

from django_tables2_column_shifter.tables import ColumnShiftTable
from django_tables2_column_shifter.tables import (
ColumnShiftTableBootstrap2, # If you user bootstrap2
ColumnShiftTableBootstrap3, # If you user bootstrap3
ColumnShiftTableBootstrap4, # If you user bootstrap3
ColumnShiftTableBootstrap5, # If you user bootstrap4
)
from app.models import MyModel

# By default you probably inherit from django_table2.Table
# Change inherit to ColumnShiftTable
class MyModelTable(ColumnShiftTable):
# Change inherit to ColumnShiftTableBootstrap4
# if you use bootstrap4
class MyModelTable(ColumnShiftTableBootstrap4):
class Meta:
model = MyModel

# or if you use bootstrap5
class MyModelTable(ColumnShiftTableBootstrap5):
class Meta:
model = MyModel




views.py - In your view, nothing changes::

from .tables import MyModelTable
Expand All @@ -139,15 +165,23 @@ To use app, you must inherit your table class from ``django_tables2_column_shift
table = MyModelTable(queryset)
return render(request, 'template.html', {'table': table})

template.html - use default render_table tag to display table object (using bootstrap3 / bootstrap4)::
template.html - use default render_table tag to display table object (using bootstrap3 / bootstrap4 / bootstrap5)::

{% extends "base.html" %}
{% load django_tables2 %}
{% render_table table %}

To retrieve the invisible columns you can use the ``$.django_tables2_column_shifter_hidden()`` API. You can either pass the 0-based index of the table in the page (i.e use ``$.django_tables2_column_shifter_hidden(1)`` to get the hidden columns for the 2nd table in the page) or just use it without parameters to retrieve the hidden columns for the first table. This API returns an array with the invisible column names.
### JS API:
To retrieve the invisible columns you can use the ``$.django_tables2_column_shifter_hidden()`` js API.
You can either pass the 0-based index of the table in the page (i.e use ``$.django_tables2_column_shifter_hidden(1)``
to get the hidden columns for the 2nd table in the page) or just use it without parameters to retrieve the hidden columns
for the first table. This API returns an array with the invisible column names.

These columns can then be used when you want to export only the visible columns, ie when the user clicks on the export button it would append an ``&excluded_columns=col1,col2`` to the export button's ``href`` which would then be used by the django-tables2 ``TableExporter`` (http://django-tables2.readthedocs.io/en/latest/pages/export.html#excluding-columns) to exclude these cols, i.e something like
These columns can then be used when you want to export only the visible columns,
ie when the user clicks on the export button it would append an ``&excluded_columns=col1,col2``
to the export button's ``href`` which would then be used by the django-tables2 ``TableExporter``
(http://django-tables2.readthedocs.io/en/latest/pages/export.html#excluding-columns) to exclude
these cols, i.e something like

exporter = TableExport('csv', table, exclude_columns=self.request.GET.get('excluded_columns').split(',))

Expand All @@ -157,6 +191,21 @@ Bootstrap2 (support for old projects):
If you use Bootstrap v2 in your project then your Table class should inherit from `ColumnShiftTableBootstrap2`
imported from `django_tables2_column_shifter.tables`.

Bootstrap3 (support for old projects):
--------------------------------------
If you use Bootstrap v3 in your project then your Table class should inherit from `ColumnShiftTableBootstrap3`
imported from `django_tables2_column_shifter.tables`.

Bootstrap4 (support for old projects):
--------------------------------------
If you use Bootstrap v4 in your project then your Table class should inherit from `ColumnShiftTableBootstrap4`
imported from `django_tables2_column_shifter.tables`.

Bootstrap3 (support for old projects):
--------------------------------------
If you use Bootstrap v5 in your project then your Table class should inherit from `ColumnShiftTableBootstrap5`
imported from `django_tables2_column_shifter.tables`.


Warnings:
----------
Expand All @@ -168,9 +217,15 @@ Warnings:
{% render_table queryset %} {# not work #}


- **Warning** : - If you use a different template than ``django_tables2_column_shifter/table.html``
- **Warning** : - If you use a different template than ``django_tables2_column_shifter/bootstrap*.html``
to render your table, probably django-tables2-column-shifter will not be work.
Your custom template should inherit from ``django_tables2_column_shifter/table.html``
Your custom template should inherit from ``django_tables2_column_shifter/bootstrap*.html``

- **Warning** : - Since version 2.0 the default template is not used for Table class.
Moreover template ``django_tables2_column_shifter/table.html`` by default inherit from
``django_tables2_column_shifter/bootstrap4.html``




Customizing:
Expand All @@ -183,15 +238,15 @@ Customizing:

2. To disable shifter mechanism - set ``False`` to ``shift_table_column`` in your table class (default value is True)::

class MyModelTable(ColumnShiftTable):
class MyModelTable(ColumnShiftTableBootstrap5):
shift_table_column = False
...


3. By default, all columns from sequence are visible, if you want limit visible columns,
override method ``get_column_default_show(self)`` like that::

class MyModelTable(ColumnShiftTable):
class MyModelTable(ColumnShiftTableBootstrap5):
def get_column_default_show(self):
self.column_default_show = ['column1', 'column2']
return super(MyModelTable, self).get_column_default_show()
Expand Down
2 changes: 1 addition & 1 deletion django_tables2_column_shifter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION = (0, 5, 2)
VERSION = (2, 0, 0)
__version__ = ".".join(str(i) for i in VERSION)
23 changes: 23 additions & 0 deletions django_tables2_column_shifter/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,26 @@ class ColumnShiftTableBootstrap2(ColumnShiftTable):
Table class compatible with bootstrap 2
"""
dropdown_button_css = "btn btn-small"
shifter_template = "django_tables2_column_shifter/bootstrap2.html"


class ColumnShiftTableBootstrap3(ColumnShiftTable):
"""
Table class compatible with bootstrap 3
"""
shifter_template = "django_tables2_column_shifter/bootstrap3.html"


class ColumnShiftTableBootstrap4(ColumnShiftTable):
"""
Table class compatible with bootstrap 4
"""
shifter_template = "django_tables2_column_shifter/bootstrap4.html"


class ColumnShiftTableBootstrap5(ColumnShiftTable):
"""
Table class compatible with bootstrap 5
"""
dropdown_button_css = "btn btn-light btn-sm"
shifter_template = "django_tables2_column_shifter/bootstrap5.html"
Loading

0 comments on commit 047c698

Please sign in to comment.