Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Upgrade Datasette #6

Merged
merged 6 commits into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .ebextensions/nginx.config
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ files:
text/csv attachment;
}

include mime.types;
types {
application/x-font-ttf ttc ttf;
text/csv csv;
text/plain txt;
}

server {
Expand All @@ -39,7 +37,7 @@ files:

gzip on;
gzip_comp_level 4;
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript text/csv;

if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
set $year $1;
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-e git+https://github.com/simonw/csvs-to-sqlite.git@2830a5850cdd018c11247cde08a199aff1255205#egg=csvs_to_sqlite
-e git+https://github.com/simonw/datasette.git@0.14#egg=datasette
-e git+https://github.com/simonw/datasette.git@0.19#egg=datasette
aiofiles==0.3.2
click-default-group==1.2
click==6.7
Expand All @@ -9,6 +9,8 @@ Jinja2==2.10
MarkupSafe==1.0
numpy==1.14.0
pandas==0.20.3
Pint==0.8.1
pluggy==0.6.0
py-lru-cache==0.1.4
python-dateutil==2.6.1
pytz==2017.3
Expand Down
29 changes: 19 additions & 10 deletions static/css/app.v2.css
Original file line number Diff line number Diff line change
Expand Up @@ -535,21 +535,30 @@ hr {
text-align: center;
}
.rangeselector,
.dbsearch, .back-btn, a.back-btn {
position: relative;
display: inline-block;
width: 260px;
height: auto;
padding: 15px;
margin: 10px;
font-size: 16px;
border-radius: 8px;
.dbsearch,
.back-btn,
a.back-btn {
background-color: #3c9076;
border-radius: 8px;
color: white;
display: inline-block;
font-size: 16px;
font-weight: bold;
vertical-align: top;
height: auto;
margin: 10px;
padding: 15px;
position: relative;
text-align: center;
vertical-align: top;
width: 260px;
}

.back-btn:hover,
a.back-btn:hover {
background-color: #9ee6d0;
text-decoration: none;
}

.roundcaveat {
color: #9ee6d0;
}
Expand Down
14 changes: 8 additions & 6 deletions templates/error.html → templates/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
<div style="padding: 1em; margin: 1em 0; border: 3px solid red;">{{ error }}</div>
{% endif %}

<form class="sql" action="/{{ database }}-{{ database_hash }}" method="get">
<h3>Custom SQL query</h3>
{% if database %}
<form class="sql" action="/{{ database }}-{{ database_hash }}" method="get">
<h3>Custom SQL query</h3>

<p><textarea name="sql"></textarea></p>
<p><textarea name="sql"></textarea></p>

<p><input type="submit" value="Run SQL"></p>
</form>
<p><input type="submit" value="Run SQL"></p>
</form>

{% include "_codemirror_foot.html" %}
{% include "_codemirror_foot.html" %}
{% endif %}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error handling was changed in the new Datasette.


{% endblock %}
13 changes: 11 additions & 2 deletions templates/_rows_and_columns.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
<thead title="Click to toggle extra columns">
<tr>
{% for column in display_columns %}
<th scope="col" class="{{ column }}">
{{ col_name[column] | default(column) }}
{% set name = col_name[column.name] | default(column.name) %}
<th scope="col" class="{{ column.name }}">
{% if not column.sortable %}
{{ name }}
{% else %}
{% if column.name == sort %}
<a href="{{ path_with_added_args(request, {'_sort_desc': column.name, '_sort': None, '_next': None}) }}" rel="nofollow">{{ name }}&nbsp;▲</a>
{% else %}
<a href="{{ path_with_added_args(request, {'_sort': column.name, '_sort_desc': None, '_next': None}) }}" rel="nofollow">{{ name }}{% if column.name == sort_desc %}&nbsp;▼{% endif %}</a>
{% endif %}
{% endif %}
</th>
{% endfor %}
</tr>
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<a href="/salaries/2017+Maryland+state+salaries?organization__like=GENERAL+ASSEMBLY+OF+MARYLAND">General Assembly</a>
<a href="/salaries/2017+Maryland+state+salaries?organization__contains=UNIVERSITY">Public universities</a>
<a href="/salaries/2017+Maryland+state+salaries?organization__like=DEPARTMENT+OF+STATE+POLICE">State police</a>
<a href="/salaries/Top-Earners">Top Earners</a>
<a href="/salaries/2017+Maryland+state+salaries?_sort_desc=ytd_gross_earnings">Top Earners</a>
</span>
<div id="share-tools">
<span class="icon-facebook js-click"></span>
Expand Down
2 changes: 1 addition & 1 deletion templates/database.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<form class="sql" action="/{{ database }}-{{ database_hash }}" method="get">
<h3>Custom SQL query</h3>
<p>Note: Database uses <a href="https://www.sqlite.org/lang.html">SQLite</a> syntax.</p>
<p><textarea name="sql">select * from {{ tables[0].name|escape_table_name }}</textarea></p>
<p><textarea name="sql">select * from {{ tables[0].name|escape_sqlite }}</textarea></p>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

escape_table_name was removed and replaced in the new Datasette.

<p><input type="submit" value="Custom SQL Query"></p>
</form>

Expand Down
2 changes: 1 addition & 1 deletion templates/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h2 class="title">{{ canned_query.replace("-", " ") }}</h2>
<form class="sql" action="/{{ database }}-{{ database_hash }}" method="get">
<h3>Custom SQL query{% if rows %} returning {% if truncated %}more than {% endif %}{{ "{:,}".format(rows|length) }} row{% if rows|length == 1 %}{% else %}s{% endif %}{% endif %}</h3>
{% if editable %}
<p><textarea name="sql">{% if query and query.sql %}{{ query.sql }}{% else %}select * from {{ tables[0].name|escape_table_name }}{% endif %}</textarea></p>
<p><textarea name="sql">{% if query and query.sql %}{{ query.sql }}{% else %}select * from {{ tables[0].name|escape_sqlite }}{% endif %}</textarea></p>
{% else %}
<pre>{% if query %}{{ query.sql }}{% endif %}</pre>
{% endif %}
Expand Down
31 changes: 29 additions & 2 deletions templates/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
{% endfor %}
<div class="dbsearch filter-row">
<div class="select-wrapper">
Filter:
<select name="_filter_column">
<option value="">- column -</option>
{% for c in filter_columns %}
Expand All @@ -60,8 +59,36 @@
</select>
</div>
<input type="text" name="_filter_value" class="filter-value">
<input type="submit" class="full-width" value="{% if filters.has_selections() %}Apply filters{% else %}Add filter{% endif %}">
</div>

{% if is_sortable %}
<div class="dbsearch filter-row">
Sort by:
<div class="select-wrapper">
<select name="_sort" id="sort_by">
<option value="">Default</option>
{% for column in display_columns %}
{% if column.sortable and column.name != "rowid" %}
<option
value="{{ column.name }}"
{% if column.name == sort or column.name == sort_desc %}selected{% endif %}>
{{- col_name[column.name] | default(column.name) -}}
</option>
{% endif %}
{% endfor %}
</select>
</div>
<label class="sort_by_desc">
<input
type="checkbox"
name="_sort_by_desc"
{% if sort_desc %}checked{% endif %}>
Descending
</label>
</div>
{% endif %}

<button type="submit" class="dbsearch">Apply</button>
<a class="back-btn" href="/">Back to main search</a>

</form>
Expand Down