-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Column Class, extra column option, documentation and extra test
- Loading branch information
1 parent
2af4af1
commit 9bfa525
Showing
16 changed files
with
345 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from typing import Callable | ||
|
||
from django.db.models import Model | ||
|
||
|
||
class BaseColumn: | ||
def __init__(self, column_field: str, column_header: str) -> None: | ||
self.column_field = column_field | ||
self.column_header = column_header | ||
|
||
def get_value(self, instance: Model): | ||
"""Return the column value for a given instance.""" | ||
return getattr(instance, self.column_field) | ||
|
||
|
||
class TableColumn(BaseColumn): | ||
pass | ||
|
||
|
||
class TableExtraColumn(BaseColumn): | ||
def __init__( | ||
self, column_field: str, column_header: str, function: Callable | ||
) -> None: | ||
super().__init__(column_field, column_header) | ||
self.function = function | ||
|
||
def get_value(self, instance: Model): | ||
"""Return the column value for a given instance.""" | ||
return self.function(instance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import sys | ||
from datetime import datetime | ||
|
||
import django | ||
|
||
sys.path.insert(0, os.path.abspath("..")) | ||
|
||
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings" | ||
|
||
|
||
django.setup() | ||
|
||
|
||
project = "django-table-sort" | ||
author = "Eduardo Leyva" | ||
copyright = f"{datetime.now().year}, {author}" | ||
|
||
version = "0.2.7" | ||
|
||
|
||
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx"] | ||
|
||
intersphinx_mapping = { | ||
"python": ("https://docs.python.org/3/", None), | ||
"sphinx": ("https://www.sphinx-doc.org/en/master/", None), | ||
} | ||
|
||
intersphinx_disabled_domains = ["std"] | ||
|
||
html_theme = "sphinx_rtd_theme" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
======== | ||
django-table-sort | ||
======== | ||
|
||
.. image:: https://results.pre-commit.ci/badge/github/TheRealVizard/django-table-sort/main.svg | ||
:target: https://results.pre-commit.ci/latest/github/TheRealVizard/django-table-sort/main | ||
:alt: pre-commit.ci status | ||
|
||
.. image:: https://readthedocs.org/projects/django-table-sort/badge/?version=latest | ||
:target: https://django-table-sort.readthedocs.io/en/latest/?badge=latest | ||
:alt: Documentation Status | ||
|
||
.. image:: https://codecov.io/gh/TheRealVizard/django-table-sort/branch/main/graph/badge.svg?token=KGXHPZ6HOB | ||
:target: https://codecov.io/gh/TheRealVizard/django-table-sort | ||
:alt: codecov | ||
|
||
.. image:: https://img.shields.io/pypi/v/django-table-sort?color=blue | ||
:alt: django-table-sort | ||
|
||
.. image:: https://img.shields.io/pypi/pyversions/django-table-sort | ||
:alt: python-versions | ||
|
||
.. image:: https://img.shields.io/pypi/frameworkversions/django/django-table-sort?label=django | ||
:alt: django-versions | ||
|
||
.. image:: https://img.shields.io/pypi/l/django-table-sort?color=blue | ||
:alt: license | ||
|
||
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg | ||
:target: https://github.com/psf/black | ||
:alt: code-style-black | ||
|
||
.. image:: https://img.shields.io/pypi/dm/django-table-sort | ||
:alt: downloads | ||
|
||
Create tables with sorting links on the headers in Django templates. | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
:caption: User Guide | ||
|
||
installation | ||
usage | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
:caption: API documentation | ||
|
||
tablesort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Installation | ||
============ | ||
|
||
1. Install the package | ||
^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
You can install *django-table-sort* via pip_ from PyPI_: | ||
|
||
.. code:: console | ||
$ pip install django-table-sort | ||
Requirements | ||
------------ | ||
|
||
* Python 3.7+ | ||
* Django 3.0+ | ||
|
||
2. Add *django-table-sort* to your ``INSTALLED_APPS`` | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. code-block:: python | ||
INSTALLED_APPS = [ | ||
# ..., | ||
"django_table_sort", | ||
# ..., | ||
] | ||
3. Add the ``CSS`` file to your templates | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. code-block:: html | ||
|
||
<! -- Font Awesome 6 for the table icons --> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css" integrity="sha512-1sCRPdkRXhBV2PBLUdRb4tMg1w2YPf37qatUFeS7zlBy7jJI8Lf4VHwWfZZfpXtYSLy85pkm9GaYVYMfw5BC1A==" crossorigin="anonymous" referrerpolicy="no-referrer" /> | ||
<! -- css to use the header sort icons --> | ||
<link rel="stylesheet" href="{% static 'django_table_sort.css' %}"/> | ||
|
||
|
||
.. _PyPI: https://pypi.org/ | ||
.. _pip: https://pip.pypa.io/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
sphinx | ||
django |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
========= | ||
Tables | ||
========= | ||
|
||
.. _table-sort-class: | ||
|
||
TableSort | ||
--------- | ||
|
||
|
||
.. autoclass:: django_table_sort.table.TableSort | ||
:members: |
Oops, something went wrong.