Skip to content

Commit

Permalink
When passing linkify as dict, QUERY and FRAGMENT now lowercase (query…
Browse files Browse the repository at this point in the history
…, fragment) FRAGMENT now lowercase (query, fragment).

Update documentation to explain these features.
  • Loading branch information
benmehlman committed Nov 6, 2019
1 parent e14b529 commit f0199f2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions django_tables2/columns/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ def __call__(self, content, **kwargs):
def get_callback(cls, *args, **kwargs):
"""
This method constructs a LinkTransform and returns a callback function suitable as the linkify
parameter of Column.__init__() This may be used to access features of LinkTransform which aren't
exposed via linkify dict or tuple linkify values, for example, constructing a url which has both
positional args AND a query string.
parameter of ``Column.__init__()`` This may be used if you wish to subclass LinkTransform or to access
(future) features of LinkTransform which may not be exposed via ``linkify``.
"""
link_transform = cls(*args, **kwargs)

Expand Down Expand Up @@ -236,7 +235,9 @@ class Column:
- If `True`, the ``record.get_absolute_url()`` or the related model's
`get_absolute_url()` is used.
- If a callable is passed, the returned value is used, if it's not ``None``.
- If a `dict` is passed, it's passed on to ``~django.urls.reverse``.
- If a `dict` is passed, optional items named ``query`` (dict), and ``fragment`` (str),
if present, specify the query string and fragment (hash) elements of the url.
The remaining items are passed on to ``~django.urls.reverse`` as kwargs.
- If a `tuple` is passed, it must be either a (viewname, args) or (viewname, kwargs)
tuple, which is also passed to ``~django.urls.reverse``.
Expand Down Expand Up @@ -325,8 +326,8 @@ def __init__(
elif isinstance(linkify, (list, tuple)):
link_kwargs = dict(reverse_args=linkify)
elif isinstance(linkify, dict):
# specific uppercase keys in linkify are understood to be link_kwargs, and the rest must be reverse_args
link_kwargs = { name.lower(): linkify.pop(name) for name in ('QUERY', 'FRAGMENT') if name in linkify }
# specific keys in linkify are understood to be link_kwargs, and the rest must be reverse_args
link_kwargs = { name: linkify.pop(name) for name in ('query', 'fragment') if name in linkify }
link_kwargs['reverse_args'] = linkify
elif linkify is True:
link_kwargs = dict(accessor=self.accessor)
Expand Down

0 comments on commit f0199f2

Please sign in to comment.