kopia lustrzana https://github.com/simonw/datasette
rodzic
d76412668f
commit
7dac1c05cd
|
@ -381,17 +381,17 @@ class TableView(BaseView):
|
|||
where_clauses = []
|
||||
params = {}
|
||||
|
||||
after = special_args.get('_after')
|
||||
if after:
|
||||
next = special_args.get('_next')
|
||||
if next:
|
||||
if use_rowid:
|
||||
where_clauses.append(
|
||||
'rowid > :p{}'.format(
|
||||
len(params),
|
||||
)
|
||||
)
|
||||
params['p{}'.format(len(params))] = after
|
||||
params['p{}'.format(len(params))] = next
|
||||
else:
|
||||
pk_values = compound_pks_from_path(after)
|
||||
pk_values = compound_pks_from_path(next)
|
||||
if len(pk_values) == len(pks):
|
||||
param_counter = len(params)
|
||||
for pk, value in zip(pks, pk_values):
|
||||
|
@ -423,11 +423,11 @@ class TableView(BaseView):
|
|||
rows = list(rows)
|
||||
info = self.ds.inspect()
|
||||
table_rows = info[name]['tables'].get(table)
|
||||
after = None
|
||||
after_link = None
|
||||
next = None
|
||||
next_url = None
|
||||
if len(rows) > self.page_size:
|
||||
after = path_from_row_pks(rows[-2], pks, use_rowid)
|
||||
after_link = path_with_added_args(request, {'_after': after})
|
||||
next = path_from_row_pks(rows[-2], pks, use_rowid)
|
||||
next_url = urllib.parse.urljoin(request.url, path_with_added_args(request, {'_next': next}))
|
||||
return {
|
||||
'database': name,
|
||||
'table': table,
|
||||
|
@ -443,13 +443,13 @@ class TableView(BaseView):
|
|||
'sql': sql,
|
||||
'params': params,
|
||||
},
|
||||
'after': after,
|
||||
'next': next,
|
||||
'next_url': next_url,
|
||||
}, lambda: {
|
||||
'database_hash': hash,
|
||||
'use_rowid': use_rowid,
|
||||
'row_link': lambda row: path_from_row_pks(row, pks, use_rowid),
|
||||
'display_columns': display_columns,
|
||||
'after_link': after_link,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,8 +52,8 @@
|
|||
</tbody>
|
||||
</table>
|
||||
|
||||
{% if after_link %}
|
||||
<p><a href="{{ after_link }}">Next page</a></p>
|
||||
{% if next_url %}
|
||||
<p><a href="{{ next_url }}">Next page</a></p>
|
||||
{% endif %}
|
||||
|
||||
{% if table_definition %}
|
||||
|
|
|
@ -122,6 +122,21 @@ def test_table_with_slashes_in_name(app_client):
|
|||
}]
|
||||
|
||||
|
||||
def test_paginate(app_client):
|
||||
path = '/test_tables/no_primary_key.jsono'
|
||||
fetched = []
|
||||
count = 0
|
||||
while path:
|
||||
_, response = app_client.get(path)
|
||||
count += 1
|
||||
fetched.extend(response.json['rows'])
|
||||
path = response.json['next_url']
|
||||
if path:
|
||||
assert path.endswith(response.json['next'])
|
||||
assert 201 == len(fetched)
|
||||
assert 5 == count
|
||||
|
||||
|
||||
def test_max_returned_rows(app_client):
|
||||
_, response = app_client.get(
|
||||
'/test_tables.jsono?sql=select+content+from+no_primary_key'
|
||||
|
|
Ładowanie…
Reference in New Issue