-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linkify #590
Conversation
I don't like chaining. It confuses me (emphasis on I and me, this may be personal preference). More importantly, it tends to have magic rules. Most often "your chained function should always return type X unless [something special], then it's OK to do something else". Wouldn't it be more pythonic to add an optional parameter |
4a91de2
to
318960f
Compare
3ca5074
to
7802640
Compare
ab39bbc
to
ca7763f
Compare
django_tables2/columns/base.py
Outdated
``a`` tag. The different ways to define the ``href`` attribute: | ||
|
||
- If `True`, the ``record.get_absolute_url()`` or the related model's | ||
`get_absolute_url()` is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this does not exist or returns a non-string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code says: TypeError if it doesn't exist, no check for result I think. Might be worth giving it another glance and document a little more. Seems likely ppl will run into this when they just set link to True. Unlikely that get_absolute_url
returns non-string. When it returns None
, what happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If get_absolute_url
does not exist -> error message: If linkify=True '{}' must have a method get_absolute_url
.
The return value is used verbatim in the template, so I think that should be transparent enough?
- 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 `tuple` is passed, it must be either a (viewname, args) or (viewname, kwargs) | ||
tuple, which is also passed to ``~django.urls.reverse``. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I also saw some checks for url
and uri
attributes somewhere? Not i use anymore? Let me try and find them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed it to url
to align with get_absolute_url
, so uri
should not occur anymore.
django_tables2/columns/base.py
Outdated
@@ -65,7 +65,13 @@ def __init__(self, **kwargs): | |||
for key, value in kwargs.items(): | |||
setattr(self, key, value) | |||
|
|||
def compose_url(self, record, bound_column): | |||
def compose_url(self, **kwargs): | |||
if hasattr(self, "uri"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this in the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outdated diff...
released 2.0.0a4 |
New API to transform any column into a link column:
This allows using specialized columns (like
DateColumn
) with links, without falling back toLinkColumn
s, which do not know about dates.You can also pass a dict, which will be passed thru to
django.urls.reverse
:Still TODO: