[Python-modules-commits] [django-tables] 01/05: Import django-tables_1.0.7.orig.tar.gz

Brian May bam at moszumanska.debian.org
Wed Jan 6 09:50:29 UTC 2016


This is an automated email from the git hooks/post-receive script.

bam pushed a commit to branch master
in repository django-tables.

commit 04b8a90dfa49efcf9a9f6acb2fbbf61b5edd7d7f
Author: Brian May <bam at debian.org>
Date:   Mon Jan 4 09:47:01 2016 +1100

    Import django-tables_1.0.7.orig.tar.gz
---
 .gitignore                                         |   1 +
 .travis.yml                                        |  50 ++--
 README.md => CHANGELOG.md                          |  96 ++----
 MANIFEST.in                                        |   5 +-
 README.md                                          | 325 ++-------------------
 django_tables2/__init__.py                         |   8 +-
 django_tables2/columns/base.py                     |  15 +-
 django_tables2/columns/linkcolumn.py               |  79 +++--
 django_tables2/columns/timecolumn.py               |   5 +-
 django_tables2/rows.py                             |   7 +-
 django_tables2/tables.py                           |  71 +++--
 django_tables2/templates/django_tables2/table.html |   2 +
 django_tables2/templatetags/django_tables2.py      |  22 +-
 django_tables2/utils.py                            |  53 +---
 django_tables2/views.py                            |   4 +
 docs/index.rst                                     |  12 -
 docs/pages/api-reference.rst                       |  13 +
 example/README.rst                                 |   7 +-
 example/app/migrations/0001_initial.py             |  41 +++
 example/app/migrations/__init__.py                 |   0
 example/manage.py                                  |   3 +-
 example/settings.py                                |  55 ++--
 example/urls.py                                    |  22 +-
 requirements/common.pip                            |   2 +-
 requirements/django-1.3.x.pip                      |   2 -
 requirements/django-1.4.x.pip                      |   2 -
 requirements/django-1.5.x.pip                      |   2 -
 requirements/django-1.6.x.pip                      |   2 -
 requirements/django-1.7.x.pip                      |   2 -
 requirements/django-1.8.x.pip                      |   2 -
 setup.py                                           |  14 +-
 tests/app/models.py                                |  14 +-
 tests/app/settings.py                              |  29 +-
 tests/app/urls.py                                  |  13 +-
 tests/columns/test_booleancolumn.py                |   9 +-
 tests/columns/test_checkboxcolumn.py               |   7 +-
 tests/columns/test_datecolumn.py                   |   5 +-
 tests/columns/test_datetimecolumn.py               |   7 +-
 tests/columns/test_emailcolumn.py                  |   2 +
 tests/columns/test_filecolumn.py                   |   9 +-
 tests/columns/test_general.py                      |  27 +-
 tests/columns/test_linkcolumn.py                   |  85 +++++-
 tests/columns/test_urlcolumn.py                    |   2 +
 tests/test_config.py                               |   7 +-
 tests/test_core.py                                 |  28 +-
 tests/test_models.py                               |  29 +-
 tests/test_templates.py                            |  67 +++--
 tests/test_utils.py                                |   8 +-
 tests/test_views.py                                |   5 +-
 tests/utils.py                                     |  35 ++-
 tox.ini                                            | 102 ++-----
 51 files changed, 680 insertions(+), 734 deletions(-)

diff --git a/.gitignore b/.gitignore
index 089cd10..9aa2ebb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@
 /example/database.sqlite
 /example/.env
 /report.pylint
+.cache/
diff --git a/.travis.yml b/.travis.yml
index 2d1ce8b..b4527c2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,22 +1,36 @@
 language: python
-python:
-  - 2.7
-env:
-  - TOX_ENV=py34-dj18
-  - TOX_ENV=py34-dj17
-  - TOX_ENV=py34-dj16
-  - TOX_ENV=py34-dj15
-  - TOX_ENV=py33-dj18
-  - TOX_ENV=py33-dj17
-  - TOX_ENV=py33-dj16
-  - TOX_ENV=py33-dj15
-  - TOX_ENV=py27-dj18
-  - TOX_ENV=py27-dj17
-  - TOX_ENV=py27-dj16
-  - TOX_ENV=py27-dj15
-  - TOX_ENV=py27-dj14
-  - TOX_ENV=py27-dj13
+
+# django 1.9 is only supported on py27 and py35
+# django 1.8 is the first realease supporting py35
+matrix:
+  include:
+    - python: 2.7
+      env: TOXENV=py27-1.7
+    - python: 2.7
+      env: TOXENV=py27-1.8
+    - python: 3.3
+      env: TOXENV=py33-1.7
+    - python: 3.3
+      env: TOXENV=py33-1.8
+    - python: 3.4
+      env: TOXENV=py34-1.7
+    - python: 3.4
+      env: TOXENV=py34-1.8
+    - python: 3.4
+      env: TOXENV=py34-1.9
+    - python: 3.5
+      env: TOXENV=py35-1.8
+    - python: 3.5
+      env: TOXENV=py35-1.9
+    - python: 2.7
+      env: TOXENV=py27-master
+    - python: 3.5
+      env: TOXENV=py35-master
+
+  allow_failures:
+      - env: TOXENV=py27-master
+      - env: TOXENV=py35-master
 install:
   - pip install tox
 script:
-  - tox -e $TOX_ENV
+  - tox
diff --git a/README.md b/CHANGELOG.md
similarity index 80%
copy from README.md
copy to CHANGELOG.md
index 27277fb..a85d6ca 100644
--- a/README.md
+++ b/CHANGELOG.md
@@ -1,73 +1,29 @@
-django-tables2 - An app for creating HTML tables
-================================================
-
-[![Build status](https://travis-ci.org/bradleyayers/django-tables2.svg)](https://travis-ci.org/bradleyayers/django-tables2)
-
-django-tables2 simplifies the task of turning sets of data into HTML tables. It
-has native support for pagination and sorting. It does for HTML tables what
-`django.forms` does for HTML forms. e.g.
-
-![An example table rendered using django-tables2](http://dl.dropbox.com/u/33499139/django-tables2/example.png)
-
-Its features include:
-
-- Any iterable can be a data-source, but special support for Django querysets
-  is included.
-- The builtin UI does not rely on JavaScript.
-- Support for automatic table generation based on a Django model.
-- Supports custom column functionality via subclassing.
-- Pagination.
-- Column based table sorting.
-- Template tag to enable trivial rendering to HTML.
-- Generic view mixin.
-
-Creating a table is as simple as:
-
-    import django_tables2 as tables
-
-    class SimpleTable(tables.Table):
-        class Meta:
-            model = Simple
-
-This would then be used in a view:
-
-    def simple_list(request):
-        queryset = Simple.objects.all()
-        table = SimpleTable(queryset)
-        return render_to_response("simple_list.html", {"table": table},
-                                  context_instance=RequestContext(request))
-
-And finally in the template:
-
-    {% load django_tables2 %}
-    {% render_table table %}
-
-This example shows one of the simplest cases, but django-tables2 can do a lot
-more! Check out the [documentation](http://django-tables2.readthedocs.org/en/latest/) for more details.
-
-
-Building the documentation
-==========================
-
-If you want to build the docs from within a virtualenv, and Sphinx is installed
-globally, use:
-
-    make html SPHINXBUILD="python $(which sphinx-build)"
-
-
-Publishing a release
-====================
-
-1. Bump the version in `django-tables2/__init__.py`.
-2. Update `README.rst`.
-3. Run `python setup.py sdist upload --sign --identity=<your gpg identity>`.
-
-Change log
-==========
-
-v1.0.4
-------
-
+# Change log
+
+## v1.0.7 (2016-01-03)
+- Explicitly check if `column.verbose_name` is not None to support empty column headers (fixes #280)
+- Cleanup the example project to make it work with modern Django versions.
+- Do not sort queryset when orderable=False (#204 by [@bmihelac](https://github.com/bmihelac))
+- `show_header` attribute on `Table` allows disabling the header (#175 by [@kviktor](https://github.com/kviktor))
+- `LinkColumn` now tries to call `get_absolute_url` on a record if no `viewname` is provided (#283, fixes #231).
+- Add `request` argument to `Table.as_html()` to allow passing correct request objects instead of poorly generated ones #282
+- Add coverage reporting to build #282
+- Drop support for python 3.2 (because of coverage), support ends feb 2016 #282
+- move `build_request` from `django_table2.utils` to `tests.utils` and amend tests #282
+
+## v1.0.6 (2015-12-29)
+- Support for custom text value in LinkColumn (#277 by [@toudi](https://github.com/toudi))
+- Refactor LinkColumn.render_link() to not escape twice #279
+- Removed `Attrs` (wrapper for dict), deprecated on 2012-09-18
+- Convert README.md to rst in setup.py to make PyPI look nice (fixes #97)
+
+## v1.0.5 (2015-12-17)
+- First version released by new maintainer [@jieter](https://github.com/jieter)
+- Dropped support for django 1.5 and 1.6, add python 3.5 with django 1.8 and 1.9 to the build matrix (#273)
+- Prevent `SingleTableView` from calling `get_queryset` twice. (fixes #155)
+- Don't call managers when resolving accessors. (#214 by [@mbertheau](https://github.com/mbertheau), fixes #211)
+
+## v1.0.4 (2015-05-09)
 - Fix bug in retrieving `field.verbose_name` under Django 1.8.
 
 v1.0.3
diff --git a/MANIFEST.in b/MANIFEST.in
index 25316ae..cba5910 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,4 +1,7 @@
-include README.rst
+include README.md
+include CHANGELOG.md
+include LICENSE
+recursive-include docs *
 recursive-include django_tables2/templates *
 recursive-include django_tables2/static *
 recursive-include django_tables2/locale *
diff --git a/README.md b/README.md
index 27277fb..a69cd6d 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,4 @@
-django-tables2 - An app for creating HTML tables
-================================================
+# django-tables2 - An app for creating HTML tables
 
 [![Build status](https://travis-ci.org/bradleyayers/django-tables2.svg)](https://travis-ci.org/bradleyayers/django-tables2)
 
@@ -11,8 +10,7 @@ has native support for pagination and sorting. It does for HTML tables what
 
 Its features include:
 
-- Any iterable can be a data-source, but special support for Django querysets
-  is included.
+- Any iterable can be a data-source, but special support for Django querysets is included.
 - The builtin UI does not rely on JavaScript.
 - Support for automatic table generation based on a Django model.
 - Supports custom column functionality via subclassing.
@@ -21,33 +19,40 @@ Its features include:
 - Template tag to enable trivial rendering to HTML.
 - Generic view mixin.
 
-Creating a table is as simple as:
+# Example
 
-    import django_tables2 as tables
+Creating a table for a model `Simple` is as simple as:
 
-    class SimpleTable(tables.Table):
-        class Meta:
-            model = Simple
+```python
+import django_tables2 as tables
+
+class SimpleTable(tables.Table):
+    class Meta:
+        model = Simple
+```
 
 This would then be used in a view:
 
-    def simple_list(request):
-        queryset = Simple.objects.all()
-        table = SimpleTable(queryset)
-        return render_to_response("simple_list.html", {"table": table},
-                                  context_instance=RequestContext(request))
+```python
+def simple_list(request):
+    queryset = Simple.objects.all()
+    table = SimpleTable(queryset)
+    return render_to_response("simple_list.html", {"table": table},
+                              context_instance=RequestContext(request))
+```
 
 And finally in the template:
 
-    {% load django_tables2 %}
-    {% render_table table %}
+```
+{% load django_tables2 %}
+{% render_table table %}
+```
 
 This example shows one of the simplest cases, but django-tables2 can do a lot
 more! Check out the [documentation](http://django-tables2.readthedocs.org/en/latest/) for more details.
 
 
-Building the documentation
-==========================
+# Building the documentation
 
 If you want to build the docs from within a virtualenv, and Sphinx is installed
 globally, use:
@@ -55,285 +60,9 @@ globally, use:
     make html SPHINXBUILD="python $(which sphinx-build)"
 
 
-Publishing a release
-====================
+# Publishing a release
 
 1. Bump the version in `django-tables2/__init__.py`.
-2. Update `README.rst`.
-3. Run `python setup.py sdist upload --sign --identity=<your gpg identity>`.
-
-Change log
-==========
-
-v1.0.4
-------
-
-- Fix bug in retrieving `field.verbose_name` under Django 1.8.
-
-v1.0.3
-------
-
-- Remove setup.cfg as PyPI doesn't actually support it, instead it's a distutils2 thing that's been discontinued.
-
-v1.0.2
-------
-
-- Add setup.cfg to declare README.md for PyPI.
-
-v1.0.1
-------
-
-- Convert README to markdown so it's formatted nicely on PyPI.
-
-v1.0.0
-------
-
-- Travis CI builds pass.
-- Added Python 3.4 support.
-- Added Django 1.7 and Django 1.8 support.
-- Dropped Python 2.6 and 3.2 support.
-- Drop Django 1.2 support
-- Convert tests to using py.test.
-
-v0.16.0
--------
-
-- Django 1.8 fixes
-- `BoundColumn.verbose_name` now titlises only if no verbose_name was given.
-  `verbose_name` is used verbatim.
-- Add max_length attribute to person CharField
-- Add Swedish translation
-- Update docs presentation on readthedocs
-
-
-v0.15.0
--------
-
-- Add UK, Russian, Spanish, Portuguese, and Polish translations
-- Add support for computed table `attrs`.
-
-v0.14.0
--------
-
-- `querystring` and `seturlparam` template tags now require the request to
-  be in the context (backwards incompatible) -- #127
-- Add Travis CI support
-- Add support for Django 1.5
-- Add L10N control for columns #120 (ignored in < Django 1.3)
-- Drop Python 2.6.4 support in favour of Python 3.2 support
-- Non-queryset data ordering is different between Python 3 and 2. When
-  comparing different types, their truth values are now compared before falling
-  back to string representations of their type.
-
-v0.13.0
--------
-
-- Add FileColumn.
-
-v0.12.1
--------
-
-- When resolving an accessor, *all* exceptions are smothered into `None`.
-
-v0.12.0
--------
-
-- Improve performance by removing unnecessary queries
-- Simplified pagination:
-
-   - `Table.page` is an instance attribute (no longer `@property`)
-   - Exceptions raised by paginators (e.g. `EmptyPage`) are no longer
-     smothered by `Table.page`
-   - Pagination exceptions are raised by `Table.paginate`
-   - `RequestConfig` can handles pagination errors silently, can be disabled
-     by including `silent=False` in the `paginate` argument value
-
-- Add `DateTimeColumn` and `DateColumn` to handle formatting `datetime`
-  and timezones.
-- Add `BooleanColumn` to handle bool values
-- `render_table` can now build and render a table for a queryset, rather than
-  needing to be passed a table instance
-- Table columns created automatically from a model now use specialised columns
-- `Column.render` is now skipped if the value is considered *empty*, the
-  default value is used instead. Empty values are specified via
-  `Column.empty_values`, by default is `(None, '')` (backward incompatible)
-- Default values can now be specified on table instances or `Table.Meta`
-- Accessor's now honor `alters_data` during resolving. Fixes issue that would
-  delete all your data when a column had an accessor of `delete`
-- Add `default` and `value` to context of `TemplateColumn`
-- Add cardinality indication to the pagination area of a table
-- `Attrs` is deprecated, use `dict` instead
-
-v0.11.0
--------
-
-- Add `URLColumn` to render URLs in a data source into hyperlinks
-- Add `EmailColumn` to render email addresses into hyperlinks
-- `TemplateColumn` can now Django's template loaders to render from a file
-
-v0.10.4
--------
-
-- Fix more bugs on Python 2.6.4, all tests now pass.
-
-v0.10.3
--------
-
-- Fix issues for Python 2.6.4 -- thanks Steve Sapovits & brianmay
-- Reduce Django 1.3 dependency to Table.as_html -- thanks brianmay
-
-v0.10.2
--------
-
-- Fix MANIFEST.in to include example templates, thanks TWAC.
-- Upgrade django-attest to fix problem with tests on Django 1.3.1
-
-v0.10.1
--------
-
-- Fixed support for Django 1.4's paginator (thanks koledennix)
-- Some juggling of internal implementation. `TableData` now supports slicing
-  and returns new `TableData` instances. `BoundRows` now takes a single
-  argument `data` (a `TableData` instance).
-- Add support for `get_pagination` on `SingleTableMixin`.
-- `SingleTableMixin` and `SingleTableView` are now importable directly from
-  `django_tables2`.
-
-v0.10.0
--------
-
-- Renamed `BoundColumn.order_by` to `order_by_alias` and never returns `None`
- (**Backwards incompatible**). Templates are affected if they use something
- like:
-
-      {% querystring table.prefixed_order_by_field=column.order_by.opposite|default:column.name %}
-
-  Which should be rewritten as:
-
-      {% querystring table.prefixed_order_by_field=column.order_by_alias.next %}
-
-- Added `next` shortcut to `OrderBy` returned from `BoundColumn.order_by_alias`
-- Added `OrderByTuple.get()`
-- Deprecated `BoundColumn.sortable`, `Column.sortable`, `Table.sortable`,
-  `sortable` CSS class, `BoundColumns.itersortable`, `BoundColumns.sortable`; use `orderable` instead of
-  `sortable`.
-- Added `BoundColumn.is_ordered`
-- Introduced concept of an `order by alias`, see glossary in the docs for details.
-
-v0.9.6
-------
-
-- Fix bug that caused an ordered column's th 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 <th>.
-- 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
-  inadvertantly replacing Django's builtin `title` template filter.
-- `BoundColumn.verbose_name` no longer does `capfirst`, titlising is now the
-  responsbility of `Column.header`.
-- `BoundColumn.__unicode__` now uses `BoundColumn.header` rather than
-  `BoundColumn.verbose_name`.
-
-v0.9.1
-------
-
-- Fix version in setup.py (doh)
-
-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 didn't 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 querystring 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 couldn't 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.
+2. Update `CHANGELOG.md`.
+3. Create a tag `git tag -a v1.0.6 -m 'tagging v1.0.6'`
+4. Run `python setup.py sdist upload --sign --identity=<your gpg identity>`.
diff --git a/django_tables2/__init__.py b/django_tables2/__init__.py
index 9b33576..abebffd 100644
--- a/django_tables2/__init__.py
+++ b/django_tables2/__init__.py
@@ -1,15 +1,15 @@
 # coding: utf-8
 # pylint: disable=W0611
-from .tables  import Table
+from .tables import Table
 from .columns import (BooleanColumn, Column, CheckBoxColumn, DateColumn,
                       DateTimeColumn, EmailColumn, FileColumn, LinkColumn,
                       TemplateColumn, URLColumn, TimeColumn)
-from .config  import RequestConfig
-from .utils   import A, Attrs
+from .config import RequestConfig
+from .utils import A
 try:
     from .views import SingleTableMixin, SingleTableView
 except ImportError:
     pass
 
 
-__version__ = "1.0.4"
+__version__ = "1.0.7"
diff --git a/django_tables2/columns/base.py b/django_tables2/columns/base.py
index ea27678..4d110c6 100644
--- a/django_tables2/columns/base.py
+++ b/django_tables2/columns/base.py
@@ -1,15 +1,16 @@
 # coding: utf-8
 from __future__ import absolute_import, unicode_literals
+
+import warnings
 from collections import OrderedDict
 from itertools import islice
-import warnings
 
-from django.db.models.fields import FieldDoesNotExist
-from django import VERSION as django_version
 import six
-
+from django import VERSION as django_version
+from django.db.models.fields import FieldDoesNotExist
 from django_tables2.templatetags.django_tables2 import title
 from django_tables2.utils import A, AttributeDict, OrderBy, OrderByTuple
+
 from ..utils import python_2_unicode_compatible
 
 
@@ -247,7 +248,7 @@ class Column(object):  # pylint: disable=R0902
             if hasattr(field, "get_related_field"):
                 verbose_name = field.get_related_field().verbose_name
             else:
-                verbose_name = field.verbose_name
+                verbose_name = getattr(field, 'verbose_name', field.name)
             return cls(verbose_name=verbose_name)
 
 
@@ -453,7 +454,7 @@ class BoundColumn(object):
         person.upper should stop at person]).
         """
         # Favor an explicit defined verbose_name
-        if self.column.verbose_name:
+        if self.column.verbose_name is not None:
             return self.column.verbose_name
 
         # This is our reasonable fallback, should the next section not result
@@ -483,7 +484,7 @@ class BoundColumn(object):
                 if hasattr(field, 'field'):
                     name = field.field.verbose_name
                 else:
-                    name = field.verbose_name
+                    name = getattr(field, 'verbose_name', field.name)
         return name
 
     @property
diff --git a/django_tables2/columns/linkcolumn.py b/django_tables2/columns/linkcolumn.py
index bbe2bdd..3b15cdc 100644
--- a/django_tables2/columns/linkcolumn.py
+++ b/django_tables2/columns/linkcolumn.py
@@ -1,12 +1,14 @@
 # coding: utf-8
 from __future__ import absolute_import, unicode_literals
-from django.core.urlresolvers import reverse
-from django.utils.html import escape
-from django.utils.safestring import mark_safe
+
 import warnings
-from .base import Column, library
+
+from django.core.urlresolvers import reverse
+from django.utils.html import format_html
 from django_tables2.utils import A, AttributeDict
 
+from .base import Column, library
+
 
 class BaseLinkColumn(Column):
     """
@@ -37,11 +39,10 @@ class BaseLinkColumn(Column):
         attrs = AttributeDict(attrs if attrs is not None else
                               self.attrs.get('a', {}))
         attrs['href'] = uri
-        html = '<a {attrs}>{text}</a>'.format(
-            attrs=attrs.as_html(),
-            text=escape(text)
-        )
-        return mark_safe(html)
+
+        return format_html('<a {attrs}>{text}</a>',
+                           attrs=attrs.as_html(),
+                           text=text)
 
 
 @library.register
@@ -54,16 +55,22 @@ class LinkColumn(BaseLinkColumn):
 
     The first arguments are identical to that of
     `~django.core.urlresolvers.reverse` and allows an internal URL to be
-    described. The last argument *attrs* allows custom HTML attributes to
-    be added to the rendered ``<a href="...">`` tag.
+    described. If this argument is `None`, then `get_absolute_url`.
+    (see Django references) will be used.
+    The last argument *attrs* allows custom HTML attributes to be added to the
+    rendered ``<a href="...">`` tag.
 
     :param    viewname: See `~django.core.urlresolvers.reverse`.
+                        Or use `None` to use Model's `get_absolute_url`
     :param     urlconf: See `~django.core.urlresolvers.reverse`.
     :param        args: See `~django.core.urlresolvers.reverse`. **
     :param      kwargs: See `~django.core.urlresolvers.reverse`. **
     :param current_app: See `~django.core.urlresolvers.reverse`.
     :param       attrs: a `dict` of HTML attributes that are added to
                         the rendered ``<input type="checkbox" .../>`` tag
+    :param        text: Either static text, or a callable. If set, this
+                        value will be used to render the text inside link
+                        instead of value (default)
 
     ** In order to create a link to a URL that relies on information in the
     current row, `.Accessor` objects can be used in the *args* or
@@ -89,24 +96,43 @@ class LinkColumn(BaseLinkColumn):
         class PeopleTable(tables.Table):
             name = tables.LinkColumn('people_detail', args=[A('pk')])
 
+    In order to override the text value (i.e. <a ... >text</a>) consider
+    the following example:
+
+    .. code-block:: python
+
+        # tables.py
+        from django_tables2.utils import A  # alias for Accessor
+
+        class PeopleTable(tables.Table):
+            name = tables.LinkColumn('people_detail', text='static text', args=[A('pk')])
+            age  = tables.LinkColumn('people_detail', text=lambda record: record.name, args=[A('pk')])
+
+    In the first example, a static text would be rendered ('static text')
+    In the second example, you can specify a callable which accepts a record object (and thus
+    can return anything from it)
+
     In addition to *attrs* keys supported by `.Column`, the following are
     available:
 
     - *a* -- ``<a>`` elements in ``<td>``.
     """
-    def __init__(self, viewname, urlconf=None, args=None, kwargs=None,
-                 current_app=None, attrs=None, **extra):
+    def __init__(self, viewname=None, urlconf=None, args=None, kwargs=None,
+                 current_app=None, attrs=None, text=None, **extra):
         super(LinkColumn, self).__init__(attrs, **extra)
         self.viewname = viewname
         self.urlconf = urlconf
         self.args = args
         self.kwargs = kwargs
         self.current_app = current_app
+        self.text_value = text
 
-    def render(self, value, record, bound_column):  # pylint: disable=W0221
-        viewname = (self.viewname.resolve(record)
-                    if isinstance(self.viewname, A)
-                    else self.viewname)
+    def compose_url(self, record):
+        '''Compose the url if the column is constructed with a viewname.'''
+        if isinstance(self.viewname, A):
+            viewname = self.viewname.resolve(record)
+        else:
+            viewname = self.viewname
 
         # The following params + if statements create optional arguments to
         # pass to Django's reverse() function.
@@ -129,4 +155,21 @@ class LinkColumn(BaseLinkColumn):
             params['current_app'] = (self.current_app.resolve(record)
                                      if isinstance(self.current_app, A)
                                      else self.current_app)
-        return self.render_link(reverse(viewname, **params), text=value)
+
+        return reverse(viewname, **params)
+
+    def render(self, value, record, bound_column):  # pylint: disable=W0221
+        if self.viewname is None:
+            if not hasattr(record, 'get_absolute_url'):
+                raise TypeError('if viewname=None, record must define a get_absolute_url')
+            url = record.get_absolute_url()
+        else:
+            url = self.compose_url(record)
+
+        text_value = value
+        if self.text_value:
+            text_value = self.text_value
+            if callable(text_value):
+                text_value = text_value(record)
+
+        return self.render_link(url, text=text_value)
diff --git a/django_tables2/columns/timecolumn.py b/django_tables2/columns/timecolumn.py
index e1ed87a..ce9eb1a 100644
--- a/django_tables2/columns/timecolumn.py
+++ b/django_tables2/columns/timecolumn.py
@@ -1,9 +1,12 @@
 # coding: utf-8
 from __future__ import absolute_import, unicode_literals
+
+from django.conf import settings
 from django.db import models
+
 from .base import library
 from .templatecolumn import TemplateColumn
-from django.conf import settings
+
 
 @library.register
 class TimeColumn(TemplateColumn):
diff --git a/django_tables2/rows.py b/django_tables2/rows.py
index bd2dd0f..d73273e 100644
--- a/django_tables2/rows.py
+++ b/django_tables2/rows.py
@@ -1,8 +1,9 @@
 # coding: utf-8
-from .utils import A, getargspec
+import six
 from django.db import models
 from django.db.models.fields import FieldDoesNotExist
-import six
+
+from .utils import A, getargspec
 
 
 class BoundRow(object):
@@ -26,7 +27,7 @@ class BoundRow(object):
         >>> table = SimpleTable([{'a': 1, 'b': 2}])
         >>> row = table.rows[0]  # we only have one row, so let's use it
         >>> for cell in row:
-        ...     print cell
+        ...     print(cell)
         ...
         1
         <input type="checkbox" name="my_chkbox" value="2" />
diff --git a/django_tables2/tables.py b/django_tables2/tables.py
index 2f31069..562beca 100644
--- a/django_tables2/tables.py
+++ b/django_tables2/tables.py
@@ -1,20 +1,22 @@
 # coding: utf-8
 from __future__ import unicode_literals
-from . import columns
-from .config import RequestConfig
-from .rows import BoundRows
-from .utils import (Accessor, AttributeDict, build_request, cached_property,
-                    computed_values, OrderBy, OrderByTuple, segment, Sequence)
+
 import copy
-import sys
-from django.core.paginator       import Paginator
-from django.db.models.fields     import FieldDoesNotExist
-from django.template             import RequestContext
-from django.template.loader      import get_template
+import warnings
 from collections import OrderedDict
+
 import six
-import warnings
+from django import VERSION
+from django.core.paginator import Paginator
+from django.db.models.fields import FieldDoesNotExist
+from django.template import RequestContext
+from django.template.loader import get_template
 
+from . import columns
+from .config import RequestConfig
+from .rows import BoundRows
+from .utils import (Accessor, AttributeDict, OrderBy, OrderByTuple, Sequence,
+                    cached_property, computed_values, segment)
 
 QUERYSET_ACCESSOR_SEPARATOR = '__'
 
@@ -101,7 +103,8 @@ class TableData(object):
                 accessors += bound_column.order_by
         if hasattr(self, "queryset"):
             translate = lambda accessor: accessor.replace(Accessor.SEPARATOR, QUERYSET_ACCESSOR_SEPARATOR)
-            self.queryset = self.queryset.order_by(*(translate(a) for a in accessors))
+            if accessors:
+                self.queryset = self.queryset.order_by(*(translate(a) for a in accessors))
         else:
             self.list.sort(key=OrderByTuple(accessors).key)
 
@@ -247,6 +250,7 @@ class TableOptions(object):
         self.per_page = getattr(options, "per_page", 25)
         self.per_page_field = getattr(options, "per_page_field", "per_page")
         self.prefix = getattr(options, "prefix", "")
+        self.show_header = getattr(options, "show_header", True)
         self.sequence = Sequence(getattr(options, "sequence", ()))
         if hasattr(options, "sortable"):
             warnings.warn("`Table.Meta.sortable` is deprecated, use `orderable` instead",
@@ -257,7 +261,6 @@ class TableOptions(object):
         self.localize = getattr(options, "localize", ())
         self.unlocalize = getattr(options, "unlocalize", ())
 
-
 class TableBase(object):
     """
     A representation of a table.
@@ -339,6 +342,15 @@ class TableBase(object):
         :type: `unicode`
 
 
+    .. attribute:: show_header
+
+        If `False`, the table will not have a header (`<thead>`), default
+        value is `True`
+
+        :type: `bool`
+
+
+
     .. attribute:: prefix
 
         A prefix for querystring fields to avoid name-clashes when using
@@ -385,7 +397,8 @@ class TableBase(object):
     def __init__(self, data, order_by=None, orderable=None, empty_text=None,
                  exclude=None, attrs=None, sequence=None, prefix=None,
                  order_by_field=None, page_field=None, per_page_field=None,
-                 template=None, sortable=None, default=None, request=None):
+                 template=None, sortable=None, default=None, request=None,
+                 show_header=None):
         super(TableBase, self).__init__()
         self.exclude = exclude or ()
         self.sequence = sequence
@@ -407,6 +420,7 @@ class TableBase(object):
         self.order_by_field = order_by_field
         self.page_field = page_field
         self.per_page_field = per_page_field
+        self.show_header = show_header
         # Make a copy so that modifying this will not touch the class
         # definition. Note that this is different from forms, where the
         # copy is made available in a ``fields`` attribute.
@@ -445,17 +459,21 @@ class TableBase(object):
         if request:
             RequestConfig(request).configure(self)
 
-    def as_html(self):
+    def as_html(self, request=None):
         """
-        Render the table to a simple HTML table.
-
-        If this method is used in the request/response cycle, any links
-        generated will clobber the querystring of the request. Use the
-        ``{% render_table %}`` template tag instead.
+        Render the table to a simple HTML table, adding `request` to the context.
         """
         template = get_template(self.template)
-        request = build_request()
-        return template.render(RequestContext(request, {'table': self}))
+
+        context = {'table': self}
+
+        if request:
+            if VERSION < (1, 8):
+                context = RequestContext(request, context)
+            else:
+                context['request'] = request
+
+        return template.render(context)
 
     @property
     def attrs(self):
@@ -466,6 +484,15 @@ class TableBase(object):
         self._attrs = value
 
... 1655 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-tables.git



More information about the Python-modules-commits mailing list