Skip to content

Commit

Permalink
table_rows => table_rows_count, filtered_table_rows => filtered_table…
Browse files Browse the repository at this point in the history
…_rows_count

Renamed properties. Closes #194
  • Loading branch information
simonw committed Apr 9, 2018
1 parent c1d37fd commit a290f28
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ http://localhost:8001/History/downloads.json will return that data as JSON:
"total_bytes",
...
],
"table_rows": 576,
"table_rows_count": 576,
"rows": [
[
1,
Expand Down
16 changes: 8 additions & 8 deletions datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ async def get(self, request, as_json):
)[:5],
'tables_count': len(tables),
'tables_more': len(tables) > 5,
'table_rows': sum(t['count'] for t in tables),
'hidden_table_rows': sum(t['count'] for t in hidden_tables),
'table_rows_sum': sum(t['count'] for t in tables),
'hidden_table_rows_sum': sum(t['count'] for t in hidden_tables),
'hidden_tables_count': len(hidden_tables),
'views_count': len(info['views']),
}
Expand Down Expand Up @@ -639,11 +639,11 @@ async def data(self, request, name, hash, table):
params['search'] = search

info = self.ds.inspect()
table_rows = None
table_rows_count = None
sortable_columns = set()
if not is_view:
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)

# Allow for custom sort order
Expand Down Expand Up @@ -798,11 +798,11 @@ async def data(self, request, name, hash, table):
rows = rows[:self.page_size]

# Number of filtered rows in whole set:
filtered_table_rows = None
filtered_table_rows_count = None
if count_sql:
try:
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:
# Almost certainly hit the timeout
pass
Expand Down Expand Up @@ -858,8 +858,8 @@ async def extra_template():
'human_description_en': human_description_en,
'rows': rows[:self.page_size],
'truncated': truncated,
'table_rows': table_rows,
'filtered_table_rows': filtered_table_rows,
'table_rows_count': table_rows_count,
'filtered_table_rows_count': filtered_table_rows_count,
'columns': columns,
'primary_keys': pks,
'query': {
Expand Down
4 changes: 2 additions & 2 deletions datasette/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ <h1>{{ metadata.title or "Datasette" }}</h1>
{% for database in databases %}
<h2 style="padding-left: 10px; border-left: 10px solid #{{ database.hash[:6] }}"><a href="{{ database.path }}">{{ database.name }}</a></h2>
<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 %}
{{ "{:,}".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 %}
{% if database.views_count %}
{% if database.tables_count or database.hidden_tables_count %} - {% endif %}
Expand Down
6 changes: 3 additions & 3 deletions datasette/templates/table.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% 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 %}

{% block extra_head %}
Expand All @@ -23,8 +23,8 @@ <h1 style="padding-left: 10px; border-left: 10px solid #{{ database_hash[:6] }}"

{% block description_source_license %}{% include "_description_source_license.html" %}{% endblock %}

{% if filtered_table_rows 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 %}
{% if filtered_table_rows_count or human_description_en %}
<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 %}
</h3>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ JSON:
"total_bytes",
...
],
"table_rows": 576,
"table_rows_count": 576,
"rows": [
[
1,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ def test_sortable_and_filtered(app_client):
row for row in generate_sortable_rows(201)
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'])
assert [
r['content'] for r in expected
Expand Down

0 comments on commit a290f28

Please sign in to comment.