Skip to content

Commit 04d9176

Browse files
committed
URLize links, closes #61
1 parent 307198d commit 04d9176

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

django_sql_dashboard/templates/django_sql_dashboard/widgets/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
{% for row in result.row_lists %}
2929
<tr>
3030
{% for item in row %}
31-
<td>{% if item is None %}<span class="null">- null -</span>{% else %}{{ item }}{% endif %}</td>
31+
<td>{% if item is None %}<span class="null">- null -</span>{% else %}{{ item|urlize }}{% endif %}</td>
3232
{% endfor %}
3333
</tr>
3434
{% endfor %}

test_project/test_widgets.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,37 @@ def test_default_widget(admin_client, dashboard_db):
3030
)
3131

3232

33+
def test_basic_table_with_some_links(admin_client, dashboard_db):
34+
response = admin_client.post(
35+
"/dashboard/",
36+
{
37+
"sql": """
38+
SELECT
39+
'https://www.google.com/' as google,
40+
'http://www.yahoo.com/' as yahoo,
41+
'www.bing.com/' as bing,
42+
123 as number,
43+
'foop' as string,
44+
null as this_is_null
45+
"""
46+
},
47+
follow=True,
48+
)
49+
html = response.content.decode("utf-8")
50+
soup = BeautifulSoup(html, "html5lib")
51+
trs = soup.select("table tbody tr")
52+
row = trs[0]
53+
tds_html = [str(td) for td in row.select("td")]
54+
assert tds_html == [
55+
'<td><a href="https://www.google.com/" rel="nofollow">https://www.google.com/</a></td>',
56+
'<td><a href="http://www.yahoo.com/" rel="nofollow">http://www.yahoo.com/</a></td>',
57+
'<td><a href="http://www.bing.com/" rel="nofollow">www.bing.com/</a></td>',
58+
"<td>123</td>",
59+
"<td>foop</td>",
60+
'<td><span class="null">- null -</span></td>',
61+
]
62+
63+
3364
def test_default_widget_column_count_links(admin_client, dashboard_db):
3465
response = admin_client.post(
3566
"/dashboard/",

0 commit comments

Comments
 (0)