From da4a8721db5c96dec6b29a7ded3e853e9e002099 Mon Sep 17 00:00:00 2001 From: Tevin Joseph K O Date: Thu, 10 Mar 2016 13:22:46 +0530 Subject: [PATCH 1/3] Added feature for query string support in Links --- table/columns/linkcolumn.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/table/columns/linkcolumn.py b/table/columns/linkcolumn.py index 81ab249..f87e1f4 100644 --- a/table/columns/linkcolumn.py +++ b/table/columns/linkcolumn.py @@ -25,7 +25,7 @@ class Link(object): Represents a html 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 [] @@ -33,6 +33,7 @@ def __init__(self, text=None, viewname=None, args=None, kwargs=None, urlconf=Non self.urlconf = urlconf self.current_app = current_app self.base_attrs = attrs or {} + self.query_strings = query_strings @property def text(self): @@ -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() params['kwargs'] = {} for key, value in self.kwargs.items(): params['kwargs'][key] = (value.resolve(self.obj) @@ -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 @@ -79,6 +91,7 @@ def attrs(self): def render(self, obj): """ Render link as HTML output tag . """ + # import ipdb; ipdb.set_trace() self.obj = obj attrs = ' '.join([ '%s="%s"' % (attr_name, attr.resolve(obj)) From 97bd59f015ee454309766516ee6d12e539e94778 Mon Sep 17 00:00:00 2001 From: Tevin Joseph K O Date: Thu, 10 Mar 2016 13:25:12 +0530 Subject: [PATCH 2/3] Update linkcolumn.py --- table/columns/linkcolumn.py | 1 - 1 file changed, 1 deletion(-) diff --git a/table/columns/linkcolumn.py b/table/columns/linkcolumn.py index f87e1f4..bd18f6e 100644 --- a/table/columns/linkcolumn.py +++ b/table/columns/linkcolumn.py @@ -91,7 +91,6 @@ def attrs(self): def render(self, obj): """ Render link as HTML output tag . """ - # import ipdb; ipdb.set_trace() self.obj = obj attrs = ' '.join([ '%s="%s"' % (attr_name, attr.resolve(obj)) From be608f2f6cceccb2630c60b9b51754a6bd75ff35 Mon Sep 17 00:00:00 2001 From: Tevin Joseph K O Date: Wed, 16 Mar 2016 10:33:29 +0530 Subject: [PATCH 3/3] Removed unused ipdb --- table/columns/linkcolumn.py | 1 - 1 file changed, 1 deletion(-) diff --git a/table/columns/linkcolumn.py b/table/columns/linkcolumn.py index bd18f6e..6cb2d1d 100644 --- a/table/columns/linkcolumn.py +++ b/table/columns/linkcolumn.py @@ -56,7 +56,6 @@ def url(self): if isinstance(arg, Accessor) else arg for arg in self.args] if self.kwargs: - # import ipdb; ipdb.set_trace() params['kwargs'] = {} for key, value in self.kwargs.items(): params['kwargs'][key] = (value.resolve(self.obj)