mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
bdfb6d4f13
commit
50e817801f
2 changed files with 16 additions and 2 deletions
|
|
@ -99,6 +99,8 @@ class BaseView(HTTPMethodView):
|
||||||
)
|
)
|
||||||
if 'table' in kwargs:
|
if 'table' in kwargs:
|
||||||
should_redirect += '/' + kwargs['table']
|
should_redirect += '/' + kwargs['table']
|
||||||
|
if 'pk_path' in kwargs:
|
||||||
|
should_redirect += '/' + kwargs['pk_path']
|
||||||
if 'as_json' in kwargs:
|
if 'as_json' in kwargs:
|
||||||
should_redirect += kwargs['as_json']
|
should_redirect += kwargs['as_json']
|
||||||
if 'as_db' in kwargs:
|
if 'as_db' in kwargs:
|
||||||
|
|
@ -487,8 +489,9 @@ class RowView(BaseView):
|
||||||
params = {}
|
params = {}
|
||||||
for i, pk_value in enumerate(pk_values):
|
for i, pk_value in enumerate(pk_values):
|
||||||
params['p{}'.format(i)] = pk_value
|
params['p{}'.format(i)] = pk_value
|
||||||
rows = await self.execute(name, sql, params)
|
# rows, truncated, description = await self.execute(name, sql, params, truncate=True)
|
||||||
columns = [r[0] for r in rows.description]
|
rows, truncated, description = await self.execute(name, sql, params, truncate=True)
|
||||||
|
columns = [r[0] for r in description]
|
||||||
rows = list(rows)
|
rows = list(rows)
|
||||||
if not rows:
|
if not rows:
|
||||||
raise NotFound('Record not found: {}'.format(pk_values))
|
raise NotFound('Record not found: {}'.format(pk_values))
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,17 @@ def test_view(app_client):
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
|
def test_row(app_client):
|
||||||
|
_, response = app_client.get('/test_tables/simple_primary_key/1', allow_redirects=False)
|
||||||
|
assert response.status == 302
|
||||||
|
assert response.headers['Location'].endswith('/1')
|
||||||
|
_, response = app_client.get('/test_tables/simple_primary_key/1')
|
||||||
|
assert response.status == 200
|
||||||
|
_, response = app_client.get('/test_tables/simple_primary_key/1.jsono')
|
||||||
|
assert response.status == 200
|
||||||
|
assert [{'pk': '1', 'content': 'hello'}] == response.json['rows']
|
||||||
|
|
||||||
|
|
||||||
TABLES = '''
|
TABLES = '''
|
||||||
CREATE TABLE simple_primary_key (
|
CREATE TABLE simple_primary_key (
|
||||||
pk varchar(30) primary key,
|
pk varchar(30) primary key,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue