Skip to content

Commit

Permalink
Merge pull request #32 from djk2/issue#29
Browse files Browse the repository at this point in the history
Issue#29 - Add possibility to exclude columns from shifting
  • Loading branch information
djk2 committed Apr 6, 2023
2 parents 90695d5 + 5f06b35 commit ac496b2
Show file tree
Hide file tree
Showing 18 changed files with 291 additions and 199 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ jobs:

tests:

runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.6, 3.8]
python-version: ['3.6', '3.8', '3.10']

steps:
- uses: actions/checkout@v2
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
CHANGELOG
===========

v. 2.1.0
--------

* Add possibility to exclude columns from shifting via `column_excluded`
* Support for Python 3.10
* Support for Django 4.0
* Support for Django 4.2
* Support django-tables2 v2.5.3

v. 2.0.3
--------

Expand Down
23 changes: 18 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Using JQuery, Bootstrap3 or Bootstrap4 or Bootstrap5 and Django >=1.9.
**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:
Your `Table` classes should inherit from:
`django_tables2_column_shifter.tables.ColumnShiftTableBootstrap5`.

Now you should inherit from:
Expand All @@ -38,14 +38,14 @@ Using JQuery, Bootstrap3 or Bootstrap4 or Bootstrap5 and Django >=1.9.

**Tested by tox with:**

* Python :3.6, 3.8
* Django : 1.9, 1.10, 1.11, 2.0, 2.1, 3.0, 3.1, 3.2, master
* django-tables2 : 1.5, 1.6, ..., 1.21, 2.0, 2.1, 2.2, 2.3, master
* Python :3.6, 3.8, 3.10
* Django : 1.9, 1.10, 1.11, 2.0, 2.1, 3.0, 3.1, 3.2, 4.0, 4.2, master
* django-tables2 : 1.15, ..., 1.21, 2.0, 2.1, 2.2, 2.3, 2.5, master

**Supported:**

* Django >= 1.9
* django-tables2 >= 1.5.0 (earlier version probably will be work but wasn't tested)
* django-tables2 >= 1.15 (earlier version probably will work but wasn't tested)
* **bootstrap2** / **bootstrap3** / **bootstrap4** / **bootstrap4.1.3** / **bootstrap5 beta3**
* **JQuery**

Expand Down Expand Up @@ -264,6 +264,19 @@ Customizing:
self.column_default_show = ['column1', 'column2']
return super(MyModelTable, self).get_column_default_show()

4. By default, all columns from sequence are visible, if you want exclude some colmumns and
block ability to manipulate then, use: ``column_excluded``

class MyModelTable(ColumnShiftTableBootstrap5):
column_excluded = ['ex_column1', 'ex_column2']

or

class MyModelTable(ColumnShiftTableBootstrap5):
def get_column_excluded(self):
self.column_excluded = ['ex_column1', 'ex_column2']
return super(MyModelTable, self).get_column_excluded()


Run demo:
---------
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 = (2, 0, 3)
VERSION = (2, 1, 0)
__version__ = ".".join(str(i) for i in VERSION)
14 changes: 10 additions & 4 deletions django_tables2_column_shifter/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class ColumnShiftTable(tables.Table):
# Which columns are visible by default
column_default_show = None

# List of columns to exclude from choice
column_excluded = None

# Shifter template for tabel inherit from django_table2/bootstrap.html
shifter_template = "django_tables2_column_shifter/table.html"

Expand All @@ -30,10 +33,13 @@ def get_column_default_show(self):
If self.column_default_show is None then
# default visible columns will be return from sequence
"""
if self.column_default_show is None:
return self.sequence
else:
return self.column_default_show
return self.column_default_show or self.sequence

def get_column_excluded(self):
"""
Excluded columns are not shown on list to choice
"""
return self.column_excluded or []

@property
def uniq_table_class_name(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,48 @@
</button>
<ul class="dropdown-menu" style="min-width:350px; padding:5px; cursor:pointer;">
{% for column in table.columns %}
{% if column.attrs.td.class in table.get_column_default_show %}
<li class="btn-shift-column"
data-td-class="{{ column.attrs.td.class }}"
data-state="on"
{% if not forloop.last %} style="border-bottom:1px solid #ccc;" {%endif %}
data-table-class-container="{{ table.uniq_table_class_name }}">
<img
src="{% static "django_tables2_column_shifter/img/check.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; opacity:0.7;"
class="ico check"
/>
<img
src="{% static "django_tables2_column_shifter/img/uncheck.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; display: none; opacity:0.7;"
class="ico uncheck"
/>
{{ column.header }}
</li>
{% else %}
<li class="btn-shift-column"
data-td-class="{{ column.attrs.td.class }}"
data-state="off"
{% if not forloop.last %} style="border-bottom:1px solid #ccc;" {%endif %}
data-table-class-container="{{ table.uniq_table_class_name }}">
<img
src="{% static "django_tables2_column_shifter/img/check.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; display:none; opacity:0.7;"
class="ico check"
/>
<img
src="{% static "django_tables2_column_shifter/img/uncheck.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; opacity:0.7;"
class="ico uncheck"
/>
{{ column.header }}
</li>
{% if column.attrs.td.class not in table.get_column_excluded %}
{% if column.attrs.td.class in table.get_column_default_show %}
<li class="btn-shift-column"
data-td-class="{{ column.attrs.td.class }}"
data-state="on"
{% if not forloop.last %} style="border-bottom:1px solid #ccc;" {%endif %}
data-table-class-container="{{ table.uniq_table_class_name }}">
<img
src="{% static "django_tables2_column_shifter/img/check.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; opacity:0.7;"
class="ico check"
/>
<img
src="{% static "django_tables2_column_shifter/img/uncheck.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; display: none; opacity:0.7;"
class="ico uncheck"
/>
{{ column.header }}
</li>
{% else %}
<li class="btn-shift-column"
data-td-class="{{ column.attrs.td.class }}"
data-state="off"
{% if not forloop.last %} style="border-bottom:1px solid #ccc;" {%endif %}
data-table-class-container="{{ table.uniq_table_class_name }}">
<img
src="{% static "django_tables2_column_shifter/img/check.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; display:none; opacity:0.7;"
class="ico check"
/>
<img
src="{% static "django_tables2_column_shifter/img/uncheck.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; opacity:0.7;"
class="ico uncheck"
/>
{{ column.header }}
</li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,48 @@
</button>
<ul class="dropdown-menu" style="min-width:350px; padding:5px; cursor:pointer;">
{% for column in table.columns %}
{% if column.attrs.td.class in table.get_column_default_show %}
<li class="btn-shift-column"
data-td-class="{{ column.attrs.td.class }}"
data-state="on"
{% if not forloop.last %} style="border-bottom:1px solid #ccc;" {%endif %}
data-table-class-container="{{ table.uniq_table_class_name }}">
<img
src="{% static "django_tables2_column_shifter/img/check.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; opacity:0.7;"
class="ico check"
/>
<img
src="{% static "django_tables2_column_shifter/img/uncheck.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; display: none; opacity:0.7;"
class="ico uncheck"
/>
{{ column.header }}
</li>
{% else %}
<li class="btn-shift-column"
data-td-class="{{ column.attrs.td.class }}"
data-state="off"
{% if not forloop.last %} style="border-bottom:1px solid #ccc;" {%endif %}
data-table-class-container="{{ table.uniq_table_class_name }}">
<img
src="{% static "django_tables2_column_shifter/img/check.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; display:none; opacity:0.7;"
class="ico check"
/>
<img
src="{% static "django_tables2_column_shifter/img/uncheck.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; opacity:0.7;"
class="ico uncheck"
/>
{{ column.header }}
</li>
{% if column.attrs.td.class not in table.get_column_excluded %}
{% if column.attrs.td.class in table.get_column_default_show %}
<li class="btn-shift-column"
data-td-class="{{ column.attrs.td.class }}"
data-state="on"
{% if not forloop.last %} style="border-bottom:1px solid #ccc;" {%endif %}
data-table-class-container="{{ table.uniq_table_class_name }}">
<img
src="{% static "django_tables2_column_shifter/img/check.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; opacity:0.7;"
class="ico check"
/>
<img
src="{% static "django_tables2_column_shifter/img/uncheck.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; display: none; opacity:0.7;"
class="ico uncheck"
/>
{{ column.header }}
</li>
{% else %}
<li class="btn-shift-column"
data-td-class="{{ column.attrs.td.class }}"
data-state="off"
{% if not forloop.last %} style="border-bottom:1px solid #ccc;" {%endif %}
data-table-class-container="{{ table.uniq_table_class_name }}">
<img
src="{% static "django_tables2_column_shifter/img/check.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; display:none; opacity:0.7;"
class="ico check"
/>
<img
src="{% static "django_tables2_column_shifter/img/uncheck.png" %}"
alt="loader"
style="width:20px; height:20px; margin-right:5px; opacity:0.7;"
class="ico uncheck"
/>
{{ column.header }}
</li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
Expand Down
Loading

0 comments on commit ac496b2

Please sign in to comment.