-
Notifications
You must be signed in to change notification settings - Fork 427
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
The linkify kwarg doesn't support adding a querystring the way LinkColumn's render_link method did. #687
Comments
So, I worked on this a little bit, and here's my example of an approach that does not change tables2:
And to use it (actual example from my application):
It is a little awkward looking but it works... It would be a lot neater if this functionality was part of the tables2 LinkTransform class.. if this idea would be accepted I will write the patch! Thanks PS: The reason I have to use the |
So, I had to go ahead with some kind of solution, so in case anyone's interested here's what I did. First, I created a subclass of tables2's
Then I wrote a function which returns a callback function that generates the url using that class:
This supports Accessors for the querystring values, but sometimes I needed to do some work on the query string values using template filters (I was doing that before, mostly the date filter).. so I made a custom accessor that lets me use template code as an accessor if I want to use a filter or do something fancy:
The way this is used is as follows:
And the generated URL would look something like:
I didn't support kwargs for reverse because I didn't need them (yet).. and my choice to do it this way has a lot to do with me being in a hurry to get work done, and I didn't want to generate tons of patches for tables2 without any discussion first.. so this solves my problems without changing tables2 (except by subclassing). But as you can see it would not be hard to incorporate these ideas right into tables2. |
@benmehlman Thanks for opening the issue and sharing your thoughts/experiments. I'd like to be able support more aspects of an url (query/hashtag) in the A patch adding something like that is very welcome! |
Thanks for reading through it, I'm happy to write a patch for For the template accessor, yes you're totally right, there is no point instantiating Template each time the accessor is rendered, it could be instantiated in Accessor's constructor since it never changes. Only the Context changes each time. If I do it that way would you accept that patch? |
We do not support python 2 anymore, so you can just import from urllib. Let's do the version without templating first, and if we are happy with that take a look at the templating. |
Prior to the addition of
linkify
it was possible to customize the behavior ofLinkColumn
by overriding therender_link
method. I did this, implementing aLinkTemplateColumn
which supported the passing of a querystring template to be rendered and appended to the url.I am now upgrading tables2 and see that
LinkColumn
has been changed to a wrapper and the url rendering has been moved toLinkTransform
where it can't be overridden.Three possible ways to get around this:
Add querystring rendering capabilities to the LinkTransform class through an extra entry in the linkify dict (ideally this would support templating).
Make the LinkTransform class swappable by adding a layer of indirection, eg.
(or we could get fancier than that...)
Make Column.link into a method that could be overridden, eg.
The alternatives (for me) that do not involve changes to tables2:
I could subclass the existing LinkTransform class, and implement querystring functionality.. then override its callable so that it would return a bare url with my querystring appended. Then pass an instance of this as the value of linkify. At least that way I take advantage of the existing linkify code and keep current with any changes to it.
Or I could simply make my own callable that renders the url, bypassing tables2's url capabilities, and pass that as the value of linkify.. but that's no fun, is it???
Thoughts?
The text was updated successfully, but these errors were encountered: