Skip to content
This repository was archived by the owner on Jul 15, 2025. It is now read-only.

Commit 35cdd8d

Browse files
Updated Docs and workflows, bump packages version (#40)
* Updated Docs and workflows, bump packages version * Updated test workflow
1 parent 63bc4fe commit 35cdd8d

File tree

4 files changed

+66
-48
lines changed

4 files changed

+66
-48
lines changed

.github/workflows/tests.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
name: Test
22

33
on:
4-
pull_request:
5-
push:
6-
branches:
7-
- main
4+
pull_request:
5+
push:
6+
branches:
7+
- main
88
jobs:
99
run:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
1313
python-version: ["3.10", "3.11"]
14-
poetry-version: ["1.2.2"]
14+
poetry-version: ["1.6.1"]
1515

1616
steps:
1717
- uses: actions/checkout@v3
1818
- name: Set up Python ${{ matrix.python-version }}
1919
uses: actions/setup-python@v4
2020
with:
21-
python-version: ${{ matrix.python-version }}
21+
python-version: ${{ matrix.python-version }}
2222
- name: Install Dependencies
2323
uses: abatilo/actions-poetry@v2
2424
with:
25-
poetry-version: ${{ matrix.poetry-version }}
25+
poetry-version: ${{ matrix.poetry-version }}
2626
- run: poetry install --with test
2727
- name: Generate coverage report
2828
run: poetry run pytest --cov=./ --cov-report=xml

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
author = "Eduardo Leyva"
1919
copyright = f"{datetime.now().year}, {author}"
2020

21-
version = "0.4.1"
21+
version = "0.6.0"
2222

2323

2424
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx"]

docs/usage.rst

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
===============
2-
Getting started
2+
Getting Started
33
===============
44

5-
The test models
5+
The Test Models
66
***************
77

8-
For example purposes, we'll use a simplified book app. Here is our models.
8+
For example purposes, we'll use a simplified book app. Here are our models.
99

1010
.. code-block:: python
1111
@@ -19,30 +19,30 @@ For example purposes, we'll use a simplified book app. Here is our models.
1919
def __str__(self):
2020
return self.name
2121
22-
Basic usage
22+
Basic Usage
2323
***********
2424

2525
.. code-block:: python
2626
2727
from django.shortcuts import render
2828
from django_table_sort.table import TableSort
29-
3029
from app.models import Person
3130
3231
3332
def view(request):
3433
table = TableSort(request, Person.objects.all())
3534
return render(request, "template.html", context={"table": table})
3635
37-
This is the basic usage of the table sort. You can use this to display Queryset and also list of items.
36+
This is the basic usage of the table sort. You can use this to display a Queryset and also a list of items.
3837

3938
.. note::
40-
The default text for the header when displaying data from a Queryset is the verbose_name of the field. For list of any other object you must set the header text using the column_names parameter.
39+
40+
The default text for the header when displaying data from a Queryset is the verbose_name of the field. For a list of any other object, you must set the header text using the column_names parameter.
4141

4242
Table CSS
4343
*********
4444

45-
You can provide the css classes that the table should have as below.
45+
You can provide the CSS classes that the table should have as shown below.
4646

4747
.. code-block:: python
4848
@@ -63,49 +63,49 @@ You can provide the css classes that the table should have as below.
6363
context["table"] = TableSort(
6464
self.request,
6565
self.object_list,
66-
table_css_clases="table table-light table-striped table-sm",
66+
table_css_classes="table table-light table-striped table-sm",
6767
sort_key_name=self.ordering_key,
6868
)
6969
return context
7070
71-
Fields and exclude
72-
******************
71+
Fields and Exclusion
72+
*******************
7373

74-
The default behavior is to show all fields of the model. If you want to show only certain field you can set this in the fields parameter as follows.
74+
The default behavior is to show all fields of the model. If you want to show only certain fields, you can set this in the fields parameter as follows.
7575

7676
.. code-block:: python
7777
7878
TableSort(request, object_list, fields=["name"])
7979
80-
This code will display only the field name in the table. You can also set which fields you don't want to display.
80+
This code will display only the field "name" in the table. You can also set which fields you don't want to display.
8181

8282
.. code-block:: python
8383
8484
TableSort(request, object_list, exclude=["age"])
8585
86-
Any field you pass in the exclude parameter will not be display, and the others that aren't, will be.
86+
Any field you pass in the exclude parameter will not be displayed, and the others that aren't will be.
8787

8888
.. warning::
89-
The current implementation looks first for the exclude field. So if you provide both fields and exclude, all the field no matter if is in the list of field you declared in the fields parameter **will not be displayed**.
9089

90+
The current implementation looks for the exclude field first. So if you provide both fields and exclude, all the fields, no matter if they are in the list of fields you declared in the fields parameter, **will not be displayed**.
9191

92-
Customizing fields headers
92+
Customizing Fields Headers
9393
**************************
9494

9595
.. code-block:: python
9696
9797
TableSort(request, object_list, fields=["age"], column_names={"age": "Age"})
9898
99-
You can set a custom header for any field. For this you can use the column_names parameter.
99+
You can set a custom header for any field. For this, you can use the column_names parameter.
100100

101101
.. warning::
102-
If you set the fields and exclude parameter to None, and you provide the column_names
103-
parameter, all the fields that are given will be displayed.
104102

105-
Adding extra columns
103+
If you set the fields and exclude parameters to None and you provide the column_names parameter, all the fields that are given will be displayed.
104+
105+
Adding Extra Columns
106106
********************
107107

108-
Sometimes you may want to add a custom column to the table column. You can do this using the added_columns parameter.
108+
Sometimes you may want to add a custom column to the table. You can do this using the added_columns parameter.
109109

110110
.. code-block:: python
111111
@@ -121,13 +121,12 @@ Sometimes you may want to add a custom column to the table column. You can do th
121121
added_columns=[(("added_column_1", "Sum"), sum)],
122122
)
123123
124-
The added_columns takes a list of tuples, following this pattern ((field_identifier, field_header), callable_function). The field_identifier is a str value to identify the field, the field_header to set the text of the header and the callable_function should be a function that takes one parameter and return a string value. The callable_function will be called for each row and the object that should be displayed is passed to as a parameter to the function.
124+
The added_columns parameter takes a list of tuples following this pattern: ((field_identifier, field_header), callable_function). The field_identifier is a string value to identify the field, the field_header is used to set the text of the header, and the callable_function should be a function that takes one parameter and returns a string value. The callable_function will be called for each row, and the object that should be displayed is passed as a parameter to the function.
125125

126-
127-
List of items
126+
List of Items
128127
*************
129128

130-
For list of items you need to set the column_names. All the field in the dictionary will be displayed.
129+
For a list of items, you need to set the column_names. All the fields in the dictionary will be displayed.
131130

132131
.. code-block:: python
133132
@@ -139,12 +138,13 @@ For list of items you need to set the column_names. All the field in the diction
139138
)
140139
141140
.. note::
142-
You can use the added_columns parameter to add other custom columns the same.
143141

144-
Primary key
142+
You can use the added_columns parameter to add other custom columns in the same way.
143+
144+
Primary Key
145145
***********
146146

147-
Sometimes you may want to show the primary key of your model, the default behavior is not to display the primary key of a Queryset since most of the time it is not useful to you this to the user.
147+
Sometimes you may want to show the primary key of your model. The default behavior is not to display the primary key of a Queryset since it is often not useful to show this to the user.
148148

149149
.. code-block:: python
150150
@@ -154,11 +154,10 @@ Sometimes you may want to show the primary key of your model, the default behavi
154154
show_primary_key=True,
155155
)
156156
157-
158-
Fields order
157+
Fields Order
159158
************
160159

161-
You can set the order to display the field in the table. For this you should use the field_order parameter.
160+
You can set the order to display the fields in the table. For this, you should usethe field_order parameter.
162161

163162
.. code-block:: python
164163
@@ -168,10 +167,28 @@ You can set the order to display the field in the table. For this you should use
168167
field_order=["age"],
169168
)
170169
171-
This will display the age as the first column in the table.
170+
This will display the "age" as the first column in the table.
172171

173172
.. note::
174-
The field will be displayed following the order you give, but if you don't include a given field this
175-
will be displayed as the last. The field_order parameter works as a priority list.
176173

177-
To see the different options you can provide please see the section :ref:`table-sort-class`.
174+
The fields will be displayed following the order you give, but if you don't include a given field, it will be displayed as the last. The field_order parameter works as a priority list.
175+
176+
177+
Customizing the Table Template
178+
****************************
179+
180+
You can customize the template used for generating the table by providing a different `template_name` parameter in the TableSort constructor. By default, the template used is `'django_table_sort/table.html'`. Here's an example:
181+
182+
.. code-block:: python
183+
184+
TableSort(
185+
request,
186+
object_list,
187+
template_name="custom_template.html",
188+
)
189+
190+
In the above example, the `'custom_template.html'` file will be used instead of the default template for generating the table.
191+
192+
To create your custom template, you can copy the contents of the default template `'django_table_sort/table.html'` and modify it according to your needs.
193+
194+
To see the different options you can provide, please see the section :ref:`table-sort-class`.

pyproject.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-table-sort"
3-
version = "0.5.0"
3+
version = "0.6.0"
44
description = "Create tables with sorting links on the headers in Django templates."
55
authors = ["TheRealVizard <vizard@divineslns.com>"]
66
readme = "README.md"
@@ -15,22 +15,23 @@ classifiers = [
1515
"Framework :: Django :: 3.2",
1616
"Framework :: Django :: 4.0",
1717
"Framework :: Django :: 4.1",
18+
"Framework :: Django :: 4.2",
1819
"Intended Audience :: Developers",
1920
"License :: OSI Approved :: MIT License",
2021
"Operating System :: OS Independent",
2122
"Programming Language :: Python",
2223
"Programming Language :: Python :: 3",
2324
"Programming Language :: Python :: 3 :: Only",
24-
"Programming Language :: Python :: 3.7",
25-
"Programming Language :: Python :: 3.8",
2625
"Programming Language :: Python :: 3.9",
2726
"Programming Language :: Python :: 3.10",
27+
"Programming Language :: Python :: 3.11",
28+
"Programming Language :: Python :: 3.12",
2829
"Topic :: Software Development :: Libraries :: Python Modules",
2930
]
3031

3132
[tool.poetry.dependencies]
32-
python = ">=3.7"
33-
django = ">=3.0"
33+
python = ">=3.9"
34+
django = ">=3.2"
3435

3536

3637
[tool.poetry.group.test.dependencies]

0 commit comments

Comments
 (0)