table_rows => table_rows_count, filtered_table_rows => filtered_table_rows_count

Renamed properties. Closes #194
This commit is contained in:
Simon Willison 2018-04-08 22:24:24 -07:00
commit a290f28caa
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
6 changed files with 17 additions and 15 deletions

View file

@ -58,7 +58,7 @@ http://localhost:8001/History/downloads.json will return that data as JSON:
"total_bytes", "total_bytes",
... ...
], ],
"table_rows": 576, "table_rows_count": 576,
"rows": [ "rows": [
[ [
1, 1,

View file

@ -385,8 +385,8 @@ class IndexView(RenderMixin):
)[:5], )[:5],
'tables_count': len(tables), 'tables_count': len(tables),
'tables_more': len(tables) > 5, 'tables_more': len(tables) > 5,
'table_rows': sum(t['count'] for t in tables), 'table_rows_sum': sum(t['count'] for t in tables),
'hidden_table_rows': sum(t['count'] for t in hidden_tables), 'hidden_table_rows_sum': sum(t['count'] for t in hidden_tables),
'hidden_tables_count': len(hidden_tables), 'hidden_tables_count': len(hidden_tables),
'views_count': len(info['views']), 'views_count': len(info['views']),
} }
@ -639,11 +639,11 @@ class TableView(RowTableShared):
params['search'] = search params['search'] = search
info = self.ds.inspect() info = self.ds.inspect()
table_rows = None table_rows_count = None
sortable_columns = set() sortable_columns = set()
if not is_view: if not is_view:
table_info = info[name]['tables'][table] table_info = info[name]['tables'][table]
table_rows = table_info['count'] table_rows_count = table_info['count']
sortable_columns = self.sortable_columns_for_table(name, table, use_rowid) sortable_columns = self.sortable_columns_for_table(name, table, use_rowid)
# Allow for custom sort order # Allow for custom sort order
@ -798,11 +798,11 @@ class TableView(RowTableShared):
rows = rows[:self.page_size] rows = rows[:self.page_size]
# Number of filtered rows in whole set: # Number of filtered rows in whole set:
filtered_table_rows = None filtered_table_rows_count = None
if count_sql: if count_sql:
try: try:
count_rows = list(await self.execute(name, count_sql, params)) count_rows = list(await self.execute(name, count_sql, params))
filtered_table_rows = count_rows[0][0] filtered_table_rows_count = count_rows[0][0]
except sqlite3.OperationalError: except sqlite3.OperationalError:
# Almost certainly hit the timeout # Almost certainly hit the timeout
pass pass
@ -858,8 +858,8 @@ class TableView(RowTableShared):
'human_description_en': human_description_en, 'human_description_en': human_description_en,
'rows': rows[:self.page_size], 'rows': rows[:self.page_size],
'truncated': truncated, 'truncated': truncated,
'table_rows': table_rows, 'table_rows_count': table_rows_count,
'filtered_table_rows': filtered_table_rows, 'filtered_table_rows_count': filtered_table_rows_count,
'columns': columns, 'columns': columns,
'primary_keys': pks, 'primary_keys': pks,
'query': { 'query': {

View file

@ -12,9 +12,9 @@
{% for database in databases %} {% for database in databases %}
<h2 style="padding-left: 10px; border-left: 10px solid #{{ database.hash[:6] }}"><a href="{{ database.path }}">{{ database.name }}</a></h2> <h2 style="padding-left: 10px; border-left: 10px solid #{{ database.hash[:6] }}"><a href="{{ database.path }}">{{ database.name }}</a></h2>
<p> <p>
{{ "{:,}".format(database.table_rows) }} rows in {{ database.tables_count }} table{% if database.tables_count != 1 %}s{% endif %}{% if database.tables_count and database.hidden_tables_count %}, {% endif %} {{ "{:,}".format(database.table_rows_sum) }} rows in {{ database.tables_count }} table{% if database.tables_count != 1 %}s{% endif %}{% if database.tables_count and database.hidden_tables_count %}, {% endif %}
{% if database.hidden_tables_count %} {% if database.hidden_tables_count %}
{{ "{:,}".format(database.hidden_table_rows) }} rows in {{ database.hidden_tables_count }} hidden table{% if database.hidden_tables_count != 1 %}s{% endif %} {{ "{:,}".format(database.hidden_table_rows_sum) }} rows in {{ database.hidden_tables_count }} hidden table{% if database.hidden_tables_count != 1 %}s{% endif %}
{% endif %} {% endif %}
{% if database.views_count %} {% if database.views_count %}
{% if database.tables_count or database.hidden_tables_count %} - {% endif %} {% if database.tables_count or database.hidden_tables_count %} - {% endif %}

View file

@ -1,6 +1,6 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block title %}{{ database }}: {{ table }}: {% if filtered_table_rows or filtered_table_rows == 0 %}{{ "{:,}".format(filtered_table_rows) }} row{% if filtered_table_rows == 1 %}{% else %}s{% endif %}{% endif %} {% block title %}{{ database }}: {{ table }}: {% if filtered_table_rows_count or filtered_table_rows_count == 0 %}{{ "{:,}".format(filtered_table_rows_count) }} row{% if filtered_table_rows_count == 1 %}{% else %}s{% endif %}{% endif %}
{% if human_description_en %}where {{ human_description_en }}{% endif %}{% endblock %} {% if human_description_en %}where {{ human_description_en }}{% endif %}{% endblock %}
{% block extra_head %} {% block extra_head %}
@ -23,8 +23,8 @@
{% block description_source_license %}{% include "_description_source_license.html" %}{% endblock %} {% block description_source_license %}{% include "_description_source_license.html" %}{% endblock %}
{% if filtered_table_rows or human_description_en %} {% if filtered_table_rows_count or human_description_en %}
<h3>{% if filtered_table_rows or filtered_table_rows == 0 %}{{ "{:,}".format(filtered_table_rows) }} row{% if filtered_table_rows == 1 %}{% else %}s{% endif %}{% endif %} <h3>{% if filtered_table_rows_count or filtered_table_rows_count == 0 %}{{ "{:,}".format(filtered_table_rows_count) }} row{% if filtered_table_rows_count == 1 %}{% else %}s{% endif %}{% endif %}
{% if human_description_en %}{{ human_description_en }}{% endif %} {% if human_description_en %}{{ human_description_en }}{% endif %}
</h3> </h3>
{% endif %} {% endif %}

View file

@ -48,7 +48,7 @@ JSON:
"total_bytes", "total_bytes",
... ...
], ],
"table_rows": 576, "table_rows_count": 576,
"rows": [ "rows": [
[ [
1, 1,

View file

@ -394,6 +394,8 @@ def test_sortable_and_filtered(app_client):
row for row in generate_sortable_rows(201) row for row in generate_sortable_rows(201)
if 'd' in row['content'] if 'd' in row['content']
] ]
assert len(expected) == response.json['filtered_table_rows_count']
assert 201 == response.json['table_rows_count']
expected.sort(key=lambda row: -row['sortable']) expected.sort(key=lambda row: -row['sortable'])
assert [ assert [
r['content'] for r in expected r['content'] for r in expected