django-tables2-2.1.1/ 0000755 0001750 0001750 00000000000 13542204315 013650 5 ustar joseph joseph django-tables2-2.1.1/requirements/ 0000755 0001750 0001750 00000000000 13542204315 016373 5 ustar joseph joseph django-tables2-2.1.1/requirements/common.pip 0000644 0001750 0001750 00000000161 13542204315 020373 0 ustar joseph joseph # mocks/stubs for tests
fudge
# xml parsing
lxml
pytz>0
tablib==0.13.0
mock
psycopg2-binary
django-filter==2.2.0
django-tables2-2.1.1/requirements/django-dev.pip 0000644 0001750 0001750 00000000034 13542204315 021120 0 ustar joseph joseph -r common.pip
Django==2.2.3
django-tables2-2.1.1/CHANGELOG.md 0000644 0001750 0001750 00000106475 13542204315 015476 0 ustar joseph joseph # Change log
## 2.1.1 (2019-09-23)
- Made `ManyToManyColumn` use `table.default` instead of a local value [#680](https://github.com/jieter/django-tables2/pull/680) by [@srtab](https://github.com/srtab)
- Removed invalid scope attribute in `
` element of `bootstrap4.html`. [#691](https://github.com/jieter/django-tables2/pull/691) by [@vlt](https://github.com/vlt)
- Fixed an issue with incorrectly disabled pagination where `SingleTableMixin` was not used together with `ListView` [#678](https://github.com/jieter/django-tables2/pull/678) by [@nieuwenhuys](https://github.com/nieuwenhuys)
## 2.1.0 (2019-07-22)
- Dropped support for python 2.7 (and django 1.11).
- Removed `django_tables2.utils.ucfirst`, use `django.utils.text.capfirst` instead.
- Removed `class="thead-default"` from bootstrap4 template ([#671](https://github.com/jieter/django-tables2/issues/671))
- Included columns with `visible=False` in export ([#677](https://github.com/jieter/django-tables2/pull/677))
- Fixed pagination when the number of pages is equal to page range plus one ([#655](https://github.com/jieter/django-tables2/pull/655))
## 2.0.6 (2019-03-26)
- Add optional 'table' kwarg to `row_attrs` callables
## 2.0.5 (2019-02-21)
- Fixes issue with wrong time format for TimeColumn [#650](https://github.com/jieter/django-tables2/pull/650) by [@IgorCode](https://github.com/IgorCode)
## 2.0.4 (2019-01-21)
- The `ValueError` raised if the QuerySet passed to a table instance did not match the value declared in `Meta.model` is now turned into a warning (fixes [#643](https://github.com/jieter/django-tables2/issues/643))
- Make sure the templates do not raise errors when `thead`/`tfoot` attributes are not defined [#624](https://github.com/jieter/django-tables2/pull/624) by [@intiocean](https://github.com/intiocean)
## 2.0.3 (2018-11-11)
- Improvements in packaging and publishing helper scripts reducing the package size considerably [#630](https://github.com/jieter/django-tables2/pull/630) by [@wtayyeb](https://github.com/wtayyeb) (fixes [#629](https://github.com/jieter/django-tables2/issues/629))
- Documentation improvements fixing [#625](https://github.com/jieter/django-tables2/issues/625), [#631](https://github.com/jieter/django-tables2/issues/631)
## 2.0.2 (2018-10-22)
- Make sure the value of the class attribute in `
` tags) by default. Previous behavior can be restored by using this method on your custom table:
```python
class MyTable(tables.Table):
# columns
def get_column_class_names(self, classes_set, bound_column):
classes_set = super(MyTable, self).get_column_class_names(classes_set, bound_column)
classes_set.add(bound_column.name)
return classes_set
```
- `verbose_name`s derived from model fields are not passed through `title()` anymore, only the first character is converted to upper case. This follows [Django's convention for verbose field names](https://docs.djangoproject.com/en/2.0/topics/db/models/#verbose-field-names): "The convention is not to capitalize the first letter of the verbose_name. Django will automatically capitalize the first letter where it needs to." (Fixes [#475](https://github.com/jieter/django-tables2/issues/475) and [#491](https://github.com/jieter/django-tables2/issues/491))
## 1.21.2 (2018-03-26)
- Moved table instantiation from `get_context_data` to `get_tables` [#554](https://github.com/jieter/django-tables2/pull/554) by [@sdolemelipone](https://github.com/sdolemelipone)
- Pass request as kwarg to `template.render()`, rather than as part of context.
(fixes [#552](https://github.com/jieter/django-tables2/issues/552))
## 1.21.1 (2018-03-12)
- Do not perform extra `COUNT()` queries for non-paginated tables. Fixes [#551](https://github.com/jieter/django-tables2/issues/551)
## 1.21.0 (2018-03-12)
- Add new method `paginated_rows` to `Table` to replace fallback to non-paginated rows in templates.
- Prevent mutation of the template context `{% render_table %}` is called from (fixes [#547](https://github.com/jieter/django-tables2/issues/547))
**Possible breaking change**: the context variables of the template `{% render_table %}` is called from is no longer available in the table's template. The `table` variable has an attribute `context`, which is the context of the calling template. Use `{{ table.context.variable }}` instead of `{{ variable }}`.
## 1.20.0 (2018-03-08)
- Define and use `get_table_data` in `MultiTableMixin` [#538](https://github.com/jieter/django-tables2/pull/538) by [@vCra](https://github.com/vCra) (fixes [#528](https://github.com/jieter/django-tables2/issues/528))
- Added `{% export_url %}` template tag.
- Allow passing a `TableData`-derived class to the data argument of the `Table` constructor, instead of a QuerySet or list of dicts.
## 1.19.0 (2018-02-02)
- `BoundColumn.attrs` does not evaluate `current_value` as `bool` [#536](https://github.com/jieter/django-tables2/pull/536) by [@pachewise](https://github.com/pachewise) (fixes [#534](https://github.com/jieter/django-tables2/issues/534))
- Allow more flexible access to cell values (especially useful for django templates) (fixes [#485](https://github.com/jieter/django-tables2/issues/485))
## 1.18.0 (2018-01-27)
- Follow relations when detecting column type for fields in `Table.Meta.fields` (fixes [#498](https://github.com/jieter/django-tables2/issues/498))
- Renamed `Table.Meta.template` to `template_name` (with deprecation warning for the former) [#542](https://github.com/jieter/django-tables2/pull/524) (fixes [#520](https://github.com/jieter/django-tables2/issues/520))
- Added Czech translation [#533](https://github.com/jieter/django-tables2/pull/533) by [@OndraRehounek](https://github.com/OndraRehounek)
- Added `table_factory` [#532](https://github.com/jieter/django-tables2/pull/532) by [@ZuluPro](https://github.com/ZuluPro)
## 1.17.1 (2017-12-14)
- Fix typo in setup.py for `extras_require`.
## 1.17.0 (2017-12-14)
- Dropped support for Django 1.8, 1.9 and 1.10.
- Add `extra_context` argument to `TemplateColumn` [#509](https://github.com/jieter/django-tables2/pull/509) by [@ad-m](https://github.com/ad-m)
- Remove unnecessary cast of record to `str` [#514](https://github.com/jieter/django-tables2/pull/514), fixes [#511](https://github.com/jieter/django-tables2/issues/511)
- Use `django.test.TestCase` for all tests, and remove dependency on pytest and reorganized some tests [#515](https://github.com/jieter/django-tables2/pull/515)
- Remove traces of django-haystack tests from the tests, there were no actual tests.
## 1.16.0 (2017-11-27)
This is the last version supporting Django 1.8, 1.9 and 1.10. Django 1.8 is only supported until April 2018, so consider upgrading to Django 1.11!
- Added `tf` dictionary to `Column.attrs` with default values for the footer, so footers now have `class` attribute by default [#501](https://github.com/jieter/django-tables2/pull/501) by [@mpasternak](https://github.com/mpasternak)
## 1.15.0 (2017-11-23)
- Added `as=varname` keyword argument to the `{% querystring %}` template tag,
fixes [#481](https://github.com/jieter/django-tables2/issues/481)
- Updated the tutorial to reflect current state of Django a bit better.
- Used `OrderedDict` rather than `dict` as the parent for `utils.AttributeDict` to make the rendered html more consistent across python versions.
- Allow reading column `attrs` from a column's attribute, allowing easier reuse of custom column attributes (fixes [#241](https://github.com/jieter/django-tables2/issues/241))
- `value` and `record` are optionally passed to the column attrs callables for data rows. [#503](https://github.com/jieter/django-tables2/pull/503), fixes [#500](https://github.com/jieter/django-tables2/issues/500)
## 1.14.2 (2017-10-30)
- Added a `row_counter` variable to the template context in `TemplateColumn` (fixes [#448](https://github.com/jieter/django-tables2/issues/488))
## 1.14.1 (2017-10-30)
- Do not fail if `orderable=False` is passed to `ManyToManyColumn()`
## 1.14.0 (2017-10-30)
- Added `separator` argument to `ManyToManyColumn`.
- Allow `mark_safe()`'d strings from `ManyToManyColumn.tranform()`
- Disabled ordering on `ManyToManyColumns` by default.
## 1.13.0 (2017-10-17)
- Made positional `data` argument to the table `__init__()` a keyword argument to make inheritance easier. Will raise a `TypeError` if omitted.
## 1.12.0 (2017-10-10)
- Allow export file name customization [#484](https://github.com/bradleyayers/django-tables2/pull/484) by [@federicobond](https://github.com/federicobond)
- Fixed a bug where template columns were not rendered for pinned rows ([#483](https://github.com/bradleyayers/django-tables2/pull/483) by [@khirstinova](https://github.com/khirstinova), fixes [#482](https://github.com/bradleyayers/django-tables2/issues/482))
## 1.11.0 (2017-09-15)
- Added Hungarian translation [#471](https://github.com/bradleyayers/django-tables2/pull/471) by [@hmikihth](https://github.com/hmikihth).
- Added TemplateColumn.value() and enhanced export docs (fixes [#470](https://github.com/bradleyayers/django-tables2/issues/470))
- Fixed display of pinned rows if table has no data. [#477](https://github.com/bradleyayers/django-tables2/pull/477) by [@khirstinova](https://github.com/khirstinova)
## 1.10.0 (2017-06-30)
- Added `ManyToManyColumn` automatically added for `ManyToManyField`s.
## 1.9.1 (2017-06-29)
- Allow customizing the value used in `Table.as_values()` (when using a `render_` method) using a `value_` method. (fixes [#458](https://github.com/bradleyayers/django-tables2/issues/458))
- Allow excluding columns from the `Table.as_values()` output. (fixes [#459](https://github.com/bradleyayers/django-tables2/issues/459))
- Fixed unicode handling for column headers in `Table.as_values()`
## 1.9.0 (2017-06-22)
- Allow computable attrs for `
` to have no HTML attributes.
## v0.9.5
- Updated example project to add `colspan` on footer cell so table border renders correctly in Webkit.
- Fix regression that caused 'sortable' class on
.
- `Table.__init__` no longer *always* calls `.order_by()` on QuerySets, fixes #55.
This does introduce a slight backwards incompatibility. `Table.order_by` now has the possibility of returning `None`, previously it would *always* return an `OrderByTuple`.
- `DeclarativeColumnsMetaclass.__new__` now uses `super()``
- Testing now requires pylint and Attest >=0.5.3
## v0.9.4
- Fix regression that caused column verbose_name values that were marked as
safe to be escaped. Now any verbose_name values that are instances of
SafeData are used unmodified.
## v0.9.3
- Fix regression in `SingleTableMixin`.
- Remove stray `print` statement.
## v0.9.2
- `SingleTableView` now uses `RequestConfig`. This fixes issues with
`order_by_field`, `page_field`, and `per_page_field` not being honored.
- Add `Table.Meta.per_page` and change `Table.paginate` to use it as default.
- Add `title` template filter. It differs from Django's built-in `title` filter
because it operates on an individual word basis and leaves words containing
capitals untouched. **Warning**: use `{% load ... from ... %}` to avoid
inadvertently replacing Django's built-in `title` template filter.
- `BoundColumn.verbose_name` no longer does `capfirst`, capitalizing is now the
responsibility of `Column.header`.
- `BoundColumn.__unicode__` now uses `BoundColumn.header` rather than
`BoundColumn.verbose_name`.
## v0.9.1
- Fix version in `setup.py`
## v0.9.0
- Add support for column attributes (see Attrs)
- Add `BoundRows.items()` to yield `(bound_column, cell)` pairs
- Tried to make docs more concise. Much stronger promotion of using
`RequestConfig` and `{% querystring %}`
## v0.8.4
- Removed random 'print' statements.
- Tweaked `paleblue` theme css to be more flexible:
- removed `whitespace: no-wrap`
- header background image to support more than 2 rows of text
## v0.8.3
- Fixed stupid import mistake. Tests did not pick it up due to them ignoring `ImportError`.
## v0.8.2
- `SingleTableView` now inherits from `ListView` which enables automatic
`foo_list.html` template name resolution (thanks dramon for reporting)
- `render_table` template tag no suppresses exceptions when `DEBUG=True`
## v0.8.1
- Fixed bug in render_table when giving it a template (issue #41)
## v0.8.0
- Added translation support in the default template via `{% trans %}`
- Removed `basic_table.html`, `Table.as_html()` now renders `table.html` but
will clobber the query string of the current request. Use the `render_table`
template tag instead
- `render_table` now supports an optional second argument -- the template to
use when rendering the table
- `Table` now supports declaring which template to use when rendering to HTML
- Django >=1.3 is now required
- Added support for using django-haystack's `SearchQuerySet` as a data source
- The default template `table.html` now includes block tags to make it easy to
extend to change small pieces
- Fixed table template parsing problems being hidden due to a subsequent
exception being raised
- `Http404` exceptions are no longer raised during a call to `Table.paginate()`,
instead it now occurs when `Table.page` is accessed
- Fixed bug where a table could not be rendered more than once if it was paginated.
- Accessing `Table.page` now returns a new page every time, rather than reusing
a single object
## v0.7.8
- Tables now support using both `sequence` and `exclude` (issue #32).
- `Sequence` class moved to `django_tables2/utils.py`.
- Table instances now support modification to the `exclude` property.
- Removed `BoundColumns._spawn_columns`.
- `Table.data`, `Table.rows`, and `Table.columns` are now attributes
rather than properties.
django-tables2-2.1.1/example/ 0000755 0001750 0001750 00000000000 13542204315 015303 5 ustar joseph joseph django-tables2-2.1.1/example/urls.py 0000644 0001750 0001750 00000002667 13542204315 016655 0 ustar joseph joseph from django.conf import settings
from django.contrib import admin
from django.urls import include, path
from django.views import static
from app.views import (
ClassBased,
FilteredPersonListView,
MultipleTables,
bootstrap,
bootstrap4,
checkbox,
country_detail,
index,
multiple,
person_detail,
semantic,
tutorial,
)
urlpatterns = [
path("", index),
path("multiple/", multiple, name="multiple"),
path("class-based/", ClassBased.as_view(), name="singletableview"),
path("class-based-multiple/", MultipleTables.as_view(), name="multitableview"),
path("class-based-filtered/", FilteredPersonListView.as_view(), name="filtertableview"),
path("checkbox/", checkbox, name="checkbox"),
path("tutorial/", tutorial, name="tutorial"),
path("bootstrap/", bootstrap, name="bootstrap"),
path("bootstrap4/", bootstrap4, name="bootstrap4"),
path("semantic/", semantic, name="semantic"),
path("admin/doc/", include("django.contrib.admindocs.urls")),
path("admin/", admin.site.urls),
path("country//", country_detail, name="country_detail"),
path("person//", person_detail, name="person_detail"),
path("media/", static.serve, {"document_root": settings.MEDIA_ROOT}),
path("i18n/", include("django.conf.urls.i18n")),
]
if settings.DEBUG:
import debug_toolbar
urlpatterns = [path("__debug__/", include(debug_toolbar.urls))] + urlpatterns
django-tables2-2.1.1/example/settings.py 0000644 0001750 0001750 00000012032 13542204315 017513 0 ustar joseph joseph from os.path import abspath, dirname, join
from django.utils.translation import gettext_lazy as _
ROOT = dirname(abspath(__file__))
DEBUG = True
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
ALLOWED_HOSTS = ["*"]
MANAGERS = ADMINS
DATABASES = {
"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": join(ROOT, "database.sqlite")}
}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = "America/Chicago"
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = "en"
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
LANGUAGES = [
("cs", _("Czech")),
("de", _("German")),
("el", _("Greek")),
("en", _("English")),
("es", _("Spanish")),
("fr", _("French")),
("hu", _("Hungarian")),
("it", _("Italian")),
("nb", _("Norwegian bokmål")),
("nl", _("Dutch")),
("pl", _("Polish")),
("pt-br", _("Portuguese (Brasil)")),
("pt-pt", _("Portuguese (Portugal)")),
("ru", _("Russian")),
("sv", _("Swedish")),
("uk", _("Ukrainian")),
("zh-hans", _("Chinese (Simplified)")),
]
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = join(ROOT, "media")
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = "/media/"
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ""
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = "/static/"
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = "/static/admin/"
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = "=nzw@mkqk)tz+_#vf%li&8sn7yn8z7!2-4njuyf1rxs*^muhvh"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": ["templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.request",
"django.template.context_processors.static",
]
},
}
]
MIDDLEWARE = (
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django.middleware.common.CommonMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.locale.LocaleMiddleware",
)
ROOT_URLCONF = "urls"
INSTALLED_APPS = (
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_filters",
"bootstrap3",
"bootstrap4",
"django_tables2",
"debug_toolbar",
"app",
)
INTERNAL_IPS = ("127.0.0.1",)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {"mail_admins": {"level": "ERROR", "class": "django.utils.log.AdminEmailHandler"}},
"loggers": {
"django.request": {"handlers": ["mail_admins"], "level": "ERROR", "propagate": True}
},
}
django-tables2-2.1.1/example/app/ 0000755 0001750 0001750 00000000000 13542204315 016063 5 ustar joseph joseph django-tables2-2.1.1/example/app/views.py 0000644 0001750 0001750 00000014014 13542204315 017572 0 ustar joseph joseph from random import choice
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
from django.utils.lorem_ipsum import words
from django.views.generic.base import TemplateView
from django_filters.views import FilterView
from django_tables2 import MultiTableMixin, RequestConfig, SingleTableMixin, SingleTableView
from django_tables2.export.views import ExportMixin
from django_tables2.paginators import LazyPaginator
from .data import COUNTRIES
from .filters import PersonFilter
from .models import Country, Person
from .tables import (
Bootstrap4Table,
BootstrapTable,
BootstrapTablePinnedRows,
CheckboxTable,
CountryTable,
PersonTable,
SemanticTable,
ThemedCountryTable,
)
def create_fake_data():
# create some fake data to make sure we need to paginate
if Country.objects.all().count() < 50:
for country in COUNTRIES.splitlines():
name, population = country.split(";")
Country.objects.create(name=name, visits=0, population=int(population))
if Person.objects.all().count() < 500:
countries = list(Country.objects.all()) + [None]
Person.objects.bulk_create(
[Person(name=words(3, common=False), country=choice(countries)) for i in range(50)]
)
def index(request):
create_fake_data()
table = PersonTable(Person.objects.all())
RequestConfig(request, paginate={"per_page": 5}).configure(table)
return render(
request,
"index.html",
{
"table": table,
"urls": (
(reverse("tutorial"), "Tutorial"),
(reverse("multiple"), "Multiple tables"),
(reverse("filtertableview"), "Filtered tables (with export)"),
(reverse("singletableview"), "Using SingleTableMixin"),
(reverse("multitableview"), "Using MultiTableMixin"),
(reverse("bootstrap"), "template: Bootstrap 3 (bootstrap.html)"),
(reverse("bootstrap4"), "template: Bootstrap 4 (bootstrap4.html)"),
(reverse("semantic"), "template: Semantic UI (semantic.html)"),
),
},
)
def multiple(request):
qs = Country.objects.all()
example1 = CountryTable(qs, prefix="1-")
RequestConfig(request, paginate=False).configure(example1)
example2 = CountryTable(qs, prefix="2-")
RequestConfig(request, paginate={"per_page": 2}).configure(example2)
example3 = ThemedCountryTable(qs, prefix="3-")
RequestConfig(request, paginate={"per_page": 3}).configure(example3)
example4 = ThemedCountryTable(qs, prefix="4-")
RequestConfig(request, paginate={"per_page": 3}).configure(example4)
example5 = ThemedCountryTable(qs, prefix="5-")
example5.template = "extended_table.html"
RequestConfig(request, paginate={"per_page": 3}).configure(example5)
return render(
request,
"multiple.html",
{
"example1": example1,
"example2": example2,
"example3": example3,
"example4": example4,
"example5": example5,
},
)
def checkbox(request):
create_fake_data()
table = CheckboxTable(Country.objects.all(), order_by="name")
RequestConfig(request, paginate={"per_page": 15}).configure(table)
return render(request, "checkbox_example.html", {"table": table})
def bootstrap(request):
"""Demonstrate the use of the bootstrap template"""
create_fake_data()
table = BootstrapTable(Person.objects.all().select_related("country"), order_by="-name")
RequestConfig(request, paginate={"paginator_class": LazyPaginator, "per_page": 10}).configure(
table
)
return render(request, "bootstrap_template.html", {"table": table})
def bootstrap4(request):
"""Demonstrate the use of the bootstrap4 template"""
create_fake_data()
table = Bootstrap4Table(Person.objects.all(), order_by="-name")
RequestConfig(request, paginate={"per_page": 10}).configure(table)
return render(request, "bootstrap4_template.html", {"table": table})
def semantic(request):
"""Demonstrate the use of the Semantic UI template"""
create_fake_data()
table = SemanticTable(Person.objects.all(), order_by="-name")
RequestConfig(request, paginate={"per_page": 10}).configure(table)
return render(request, "semantic_template.html", {"table": table})
class ClassBased(SingleTableView):
table_class = ThemedCountryTable
queryset = Country.objects.all()
template_name = "class_based.html"
class MultipleTables(MultiTableMixin, TemplateView):
template_name = "multiTable.html"
table_pagination = {"per_page": 10}
def get_tables(self):
qs = Person.objects.all()
return [
PersonTable(qs),
PersonTable(qs, exclude=("country",)),
BootstrapTablePinnedRows(qs),
]
def tutorial(request):
table = PersonTable(
Person.objects.all(), attrs={"class": "paleblue"}, template_name="django_tables2/table.html"
)
RequestConfig(request, paginate={"per_page": 10}).configure(table)
return render(request, "tutorial.html", {"table": table})
class FilteredPersonListView(ExportMixin, SingleTableMixin, FilterView):
table_class = PersonTable
model = Person
template_name = "bootstrap_template.html"
filterset_class = PersonFilter
export_formats = ("csv", "xls")
def get_queryset(self):
return super().get_queryset().select_related("country")
def get_table_kwargs(self):
return {"template_name": "django_tables2/bootstrap.html"}
def country_detail(request, pk):
country = get_object_or_404(Country, pk=pk)
# hide the country column, as it is not very interesting for a list of persons for a country.
table = PersonTable(country.person_set.all(), extra_columns=(("country", None),))
return render(request, "country_detail.html", {"country": country, "table": table})
def person_detail(request, pk):
person = get_object_or_404(Person, pk=pk)
return render(request, "person_detail.html", {"person": person})
django-tables2-2.1.1/example/app/migrations/ 0000755 0001750 0001750 00000000000 13542204315 020237 5 ustar joseph joseph django-tables2-2.1.1/example/app/migrations/0003_auto_20180416_1020.py 0000644 0001750 0001750 00000001020 13542204315 023643 0 ustar joseph joseph # Generated by Django 2.0.1 on 2018-04-16 10:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [("app", "0002_auto_20180416_0959")]
operations = [
migrations.AlterField(
model_name="country",
name="flag",
field=models.FileField(blank=True, upload_to="country/flags/"),
),
migrations.AlterField(
model_name="country", name="tz", field=models.CharField(blank=True, max_length=50)
),
]
django-tables2-2.1.1/example/app/migrations/0002_auto_20180416_0959.py 0000644 0001750 0001750 00000001550 13542204315 023676 0 ustar joseph joseph # Generated by Django 2.0.1 on 2018-04-16 09:59
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [("app", "0001_initial")]
operations = [
migrations.CreateModel(
name="Continent",
fields=[
(
"id",
models.AutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("name", models.CharField(max_length=100)),
],
),
migrations.AddField(
model_name="country",
name="continent",
field=models.ForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, to="app.Continent"
),
),
]
django-tables2-2.1.1/example/app/migrations/0001_initial.py 0000644 0001750 0001750 00000003427 13542204315 022710 0 ustar joseph joseph # Generated by Django 1.11.5 on 2017-09-22 13:23
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="Country",
fields=[
(
"id",
models.AutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("name", models.CharField(max_length=100)),
("population", models.PositiveIntegerField(verbose_name="population")),
("tz", models.CharField(max_length=50)),
("visits", models.PositiveIntegerField()),
("commonwealth", models.NullBooleanField()),
("flag", models.FileField(upload_to="country/flags/")),
],
options={"verbose_name_plural": "countries"},
),
migrations.CreateModel(
name="Person",
fields=[
(
"id",
models.AutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("name", models.CharField(max_length=200, verbose_name="full name")),
("friendly", models.BooleanField(default=True)),
(
"country",
models.ForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, to="app.Country"
),
),
],
options={"verbose_name_plural": "people"},
),
]
django-tables2-2.1.1/example/app/migrations/__init__.py 0000644 0001750 0001750 00000000000 13542204315 022336 0 ustar joseph joseph django-tables2-2.1.1/example/app/tables.py 0000644 0001750 0001750 00000004252 13542204315 017712 0 ustar joseph joseph import django_tables2 as tables
from .models import Country, Person
class CountryTable(tables.Table):
name = tables.Column()
population = tables.Column()
tz = tables.Column(verbose_name="time zone")
visits = tables.Column()
summary = tables.Column(order_by=("name", "population"))
class Meta:
model = Country
class ThemedCountryTable(CountryTable):
class Meta:
attrs = {"class": "paleblue"}
class CheckboxTable(tables.Table):
select = tables.CheckBoxColumn(empty_values=(), footer="")
population = tables.Column(attrs={"cell": {"class": "population"}})
class Meta:
model = Country
template_name = "django_tables2/bootstrap.html"
fields = ("select", "name", "population")
class BootstrapTable(tables.Table):
id = tables.Column(linkify=True)
country = tables.Column(linkify=True)
continent = tables.Column(
accessor="country.continent.name", verbose_name="Continent", linkify=True
)
class Meta:
model = Person
template_name = "django_tables2/bootstrap.html"
exclude = ("friendly",)
class BootstrapTablePinnedRows(BootstrapTable):
class Meta(BootstrapTable.Meta):
pinned_row_attrs = {"class": "info"}
def get_top_pinned_data(self):
return [
{
"name": "Most used country: ",
"country": Country.objects.filter(name="Cameroon").first(),
}
]
class Bootstrap4Table(tables.Table):
country = tables.Column(linkify=True)
continent = tables.Column(accessor="country.continent", linkify=True)
class Meta:
model = Person
template_name = "django_tables2/bootstrap4.html"
attrs = {"class": "table table-hover"}
exclude = ("friendly",)
class SemanticTable(tables.Table):
country = tables.RelatedLinkColumn()
class Meta:
model = Person
template_name = "django_tables2/semantic.html"
exclude = ("friendly",)
class PersonTable(tables.Table):
id = tables.Column(linkify=True)
country = tables.Column(linkify=True)
class Meta:
model = Person
template_name = "django_tables2/bootstrap.html"
django-tables2-2.1.1/example/app/__init__.py 0000644 0001750 0001750 00000000000 13542204315 020162 0 ustar joseph joseph django-tables2-2.1.1/example/app/data.py 0000644 0001750 0001750 00000001552 13542204315 017351 0 ustar joseph joseph COUNTRIES = """Aruba;104822
Afghanistan;34656032
Angola;28813463
Albania;2876101
Andorra;77281
Arab World;406452690
United Arab Emirates;9269612
Argentina;43847430
Armenia;2924816
American Samoa;55599
Antigua and Barbuda;100963
Australia;24127159
Austria;8747358
Azerbaijan;9762274
Burundi;10524117
Belgium;11348159
Benin;10872298
Burkina Faso;18646433
Bangladesh;162951560
Bulgaria;7127822
Bahrain;1425171
Bahamas, The;391232
Bosnia and Herzegovina;3516816
Belarus;9507120
Belize;366954
Bermuda;65331
Bolivia;10887882
Brazil;207652865
Barbados;284996
Brunei Darussalam;423196
Bhutan;797765
Botswana;2250260
Central African Republic;4594621
Canada;36286425
Switzerland;8372098
Channel Islands;164541
Chile;17909754
China;1378665000
Cote d'Ivoire;23695919
Cameroon;23439189
Congo, Dem. Rep.;78736153
Congo, Rep.;5125821
Colombia;48653419
Comoros;795601
Cabo Verde;539560
"""
django-tables2-2.1.1/example/app/fixtures/ 0000755 0001750 0001750 00000000000 13542204315 017734 5 ustar joseph joseph django-tables2-2.1.1/example/app/fixtures/initial_data.json 0000644 0001750 0001750 00000001451 13542204315 023252 0 ustar joseph joseph [
{
"pk": 1,
"model": "app.country",
"fields": {
"tz": "Australia/Brisbane",
"name": "Australia",
"visits": 2,
"population": 20000000,
"flag": "country/flags/australia.svg"
}
},
{
"pk": 2,
"model": "app.country",
"fields": {
"tz": "NZST",
"name": "New Zealand",
"visits": 1,
"population": 12000000,
"flag": "country/flags/new_zealand.svg"
}
},
{
"pk": 4,
"model": "app.country",
"fields": {
"tz": "UTC\u22123.5",
"name": "Canada",
"visits": 1,
"population": 34447000,
"flag": "country/flags/canada.svg"
}
}
]
django-tables2-2.1.1/example/app/admin.py 0000644 0001750 0001750 00000000376 13542204315 017533 0 ustar joseph joseph from django.contrib import admin
from .models import Continent, Country
class CountryAdmin(admin.ModelAdmin):
list_per_page = 20
list_display = ("name", "continent")
admin.site.register(Country, CountryAdmin)
admin.site.register(Continent)
django-tables2-2.1.1/example/app/models.py 0000644 0001750 0001750 00000002667 13542204315 017733 0 ustar joseph joseph from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
class Continent(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Country(models.Model):
"""
Represents a geographical Country
"""
name = models.CharField(max_length=100)
population = models.PositiveIntegerField(verbose_name=_("population"))
tz = models.CharField(max_length=50, blank=True)
visits = models.PositiveIntegerField()
commonwealth = models.NullBooleanField()
flag = models.FileField(upload_to="country/flags/", blank=True)
continent = models.ForeignKey(Continent, null=True, on_delete=models.CASCADE)
class Meta:
verbose_name_plural = _("countries")
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse("country_detail", args=(self.pk,))
@property
def summary(self):
return "%s (pop. %s)" % (self.name, self.population)
class Person(models.Model):
name = models.CharField(max_length=200, verbose_name="full name")
friendly = models.BooleanField(default=True)
country = models.ForeignKey(Country, null=True, on_delete=models.CASCADE)
class Meta:
verbose_name_plural = "people"
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse("person_detail", args=(self.pk,))
django-tables2-2.1.1/example/app/filters.py 0000644 0001750 0001750 00000000320 13542204315 020100 0 ustar joseph joseph from django_filters import FilterSet
from .models import Person
class PersonFilter(FilterSet):
class Meta:
model = Person
fields = {"name": ["exact", "contains"], "country": ["exact"]}
django-tables2-2.1.1/example/__init__.py 0000644 0001750 0001750 00000000000 13542204315 017402 0 ustar joseph joseph django-tables2-2.1.1/example/manage.py 0000755 0001750 0001750 00000000363 13542204315 017112 0 ustar joseph joseph #!/usr/bin/env python3
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
django-tables2-2.1.1/example/templates/ 0000755 0001750 0001750 00000000000 13542204315 017301 5 ustar joseph joseph django-tables2-2.1.1/example/templates/bootstrap4_template.html 0000644 0001750 0001750 00000002161 13542204315 024163 0 ustar joseph joseph {% load static %}
{% load render_table from django_tables2 %}
{% load bootstrap4 %}
django_tables2 with bootstrap 4 template example
{% bootstrap_css %}
{% endblock %}
django-tables2-2.1.1/example/templates/semantic_template.html 0000644 0001750 0001750 00000001276 13542204315 023673 0 ustar joseph joseph {% load render_table from django_tables2 %}
django_tables2 with semantic template example
{% block body %}
django_tables2 with Semantic UI template example
{% render_table table %}
{% endblock %}
django-tables2-2.1.1/example/templates/tutorial.html 0000644 0001750 0001750 00000000503 13542204315 022030 0 ustar joseph joseph {% load django_tables2 %}
{% load static %}
django_tables2 with the default template example
{% render_table table %}
django-tables2-2.1.1/example/templates/bootstrap_template.html 0000644 0001750 0001750 00000003176 13542204315 024106 0 ustar joseph joseph {% load static %}
{% load django_tables2 %}
{% load bootstrap3 %}
django_tables2 with bootstrap 3 template example
{% bootstrap_css %}