Skip to content
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

Updated Link such that it supports querystrings #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion table/columns/linkcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ class Link(object):
Represents a html <a> tag.
"""
def __init__(self, text=None, viewname=None, args=None, kwargs=None, urlconf=None,
current_app=None, attrs=None):
current_app=None, attrs=None, query_strings={}):
self.basetext = text
self.viewname = viewname
self.args = args or []
self.kwargs = kwargs or {}
self.urlconf = urlconf
self.current_app = current_app
self.base_attrs = attrs or {}
self.query_strings = query_strings

@property
def text(self):
Expand All @@ -55,6 +56,7 @@ def url(self):
if isinstance(arg, Accessor) else arg
for arg in self.args]
if self.kwargs:
# import ipdb; ipdb.set_trace()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless code

params['kwargs'] = {}
for key, value in self.kwargs.items():
params['kwargs'][key] = (value.resolve(self.obj)
Expand All @@ -68,6 +70,16 @@ def url(self):
if isinstance(self.current_app, Accessor)
else self.current_app)

if self.query_strings:
for k, v in self.query_strings.items():
if self.query_strings.itervalues().next() == v:
query_strings = "?%s=%s" % (k, v.resolve(self.obj)
if isinstance(v, Accessor) else v)
else:
query_strings += "&%s=%s" % (k, v.resolve(self.obj)
if isinstance(v, Accessor) else v)
return reverse(self.viewname, **params) + query_strings

return reverse(self.viewname, **params)

@property
Expand Down