kopia lustrzana https://github.com/simonw/datasette
Search now applies to current filters
Combined search into the same form as filters. Closes #133sanic-07
rodzic
8a37baba14
commit
a802cbee74
|
@ -528,12 +528,14 @@ class TableView(RowTableShared):
|
|||
fts_table = fts_rows[0][0]
|
||||
|
||||
search = special_args.get('_search')
|
||||
search_description = None
|
||||
if search and fts_table:
|
||||
where_clauses.append(
|
||||
'rowid in (select rowid from [{fts_table}] where [{fts_table}] match :search)'.format(
|
||||
fts_table=fts_table
|
||||
)
|
||||
)
|
||||
search_description = 'search matches "{}"'.format(search)
|
||||
params['search'] = search
|
||||
|
||||
next = special_args.get('_next')
|
||||
|
@ -642,10 +644,13 @@ class TableView(RowTableShared):
|
|||
# Almost certainly hit the timeout
|
||||
pass
|
||||
|
||||
# human_filter_description combines filters AND search, if provided
|
||||
human_description = filters.human_description(extra=search_description)
|
||||
|
||||
async def extra_template():
|
||||
return {
|
||||
'database_hash': hash,
|
||||
'human_filter_description': filters.human_description(),
|
||||
'human_filter_description': human_description,
|
||||
'supports_search': bool(fts_table),
|
||||
'search': search or '',
|
||||
'use_rowid': use_rowid,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
body {
|
||||
margin: 0 1em;
|
||||
font-family: "Helvetica Neue", sans-serif;
|
||||
|
@ -107,11 +106,12 @@ form label {
|
|||
form input[type=text],
|
||||
form input[type=search] {
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 3px;
|
||||
width: 60%;
|
||||
padding: 9px 4px;
|
||||
font-family: monospace;
|
||||
display: inline-block;
|
||||
font-size: 1.1em;
|
||||
font-size: 1em;
|
||||
font-family: Helvetica, sans-serif;
|
||||
}
|
||||
@media only screen and (max-width: 576px) {
|
||||
form.sql textarea {
|
||||
|
@ -137,6 +137,16 @@ form input[type=submit] {
|
|||
.filter-row {
|
||||
margin-bottom: 0.6em;
|
||||
}
|
||||
.search-row {
|
||||
margin-bottom: 1.8em;
|
||||
}
|
||||
|
||||
.search-row label {
|
||||
font-size: 1.2em;
|
||||
padding-right: 0.5em;
|
||||
display: inline-block;
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
.select-wrapper {
|
||||
border: 1px solid #ccc;
|
||||
|
|
|
@ -24,13 +24,10 @@
|
|||
</h3>
|
||||
{% endif %}
|
||||
|
||||
{% if supports_search %}
|
||||
<form action="/{{ database }}-{{ database_hash }}/{{ table|quote_plus }}" method="get">
|
||||
<p><input type="search" name="_search" value="{{ search }}"> <input type="submit" value="Search"></p>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<form class="filters" action="/{{ database }}-{{ database_hash }}/{{ table|quote_plus }}" method="get">
|
||||
{% if supports_search %}
|
||||
<div class="search-row"><label for="_search">Search:</label><input id="_search" type="search" name="_search" value="{{ search }}"></div>
|
||||
{% endif %}
|
||||
{% for column, lookup, value in filters.selections() %}
|
||||
<div class="filter-row">
|
||||
<div class="select-wrapper">
|
||||
|
|
|
@ -359,8 +359,10 @@ class Filters:
|
|||
for filter in self._filters:
|
||||
yield filter.key, filter.display, filter.no_argument
|
||||
|
||||
def human_description(self):
|
||||
def human_description(self, extra=None):
|
||||
bits = []
|
||||
if extra:
|
||||
bits.append(extra)
|
||||
for column, lookup, value in self.selections():
|
||||
filter = self._filters_by_key.get(lookup, None)
|
||||
if filter:
|
||||
|
|
|
@ -404,6 +404,23 @@ def test_existing_filter_redirects(app_client):
|
|||
assert '?' not in response.headers['Location']
|
||||
|
||||
|
||||
def test_empty_search_parameter_gets_removed(app_client):
|
||||
path_base = app_client.get(
|
||||
'/test_tables/simple_primary_key', allow_redirects=False, gather_request=False
|
||||
).headers['Location']
|
||||
path = path_base + '?' + urllib.parse.urlencode({
|
||||
'_search': '',
|
||||
'_filter_column': 'name',
|
||||
'_filter_op': 'exact',
|
||||
'_filter_value': 'chidi',
|
||||
})
|
||||
response = app_client.get(path, allow_redirects=False, gather_request=False)
|
||||
assert response.status == 302
|
||||
assert response.headers['Location'].endswith(
|
||||
'?name__exact=chidi'
|
||||
)
|
||||
|
||||
|
||||
TABLES = '''
|
||||
CREATE TABLE simple_primary_key (
|
||||
pk varchar(30) primary key,
|
||||
|
|
Ładowanie…
Reference in New Issue