From 893c6e1f9744ffcf2f1831fa077ab3db5db22dbd Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Wed, 4 Sep 2024 22:56:46 -0400 Subject: [PATCH] better initial experience --- explorer/app_settings.py | 2 + explorer/ee/db_connections/models.py | 1 - explorer/forms.py | 7 +- explorer/templates/explorer/base.html | 6 + explorer/templates/explorer/play.html | 3 +- explorer/templates/explorer/query.html | 2 +- explorer/templates/explorer/query_list.html | 283 ++++++++++---------- explorer/views/list.py | 2 + explorer/views/mixins.py | 1 + 9 files changed, 166 insertions(+), 141 deletions(-) diff --git a/explorer/app_settings.py b/explorer/app_settings.py index 8bf69b63..ff89299a 100644 --- a/explorer/app_settings.py +++ b/explorer/app_settings.py @@ -170,6 +170,8 @@ # 500mb default max EXPLORER_MAX_UPLOAD_SIZE = getattr(settings, "EXPLORER_MAX_UPLOAD_SIZE", 500 * 1024 * 1024) +EXPLORER_HOSTED = getattr(settings, "EXPLORER_HOSTED", True) + def has_assistant(): return EXPLORER_AI_API_KEY is not None diff --git a/explorer/ee/db_connections/models.py b/explorer/ee/db_connections/models.py index 140543ac..49d853a1 100644 --- a/explorer/ee/db_connections/models.py +++ b/explorer/ee/db_connections/models.py @@ -151,7 +151,6 @@ def save(self, *args, **kwargs): DatabaseConnection.objects.filter(default=True).update(default=False) else: # If there is no default set yet, make this newly created one the default. - # Effectively this is for first-time installations. has_default = DatabaseConnection.objects.filter(default=True).exists() if not has_default: self.default = True diff --git a/explorer/forms.py b/explorer/forms.py index e025b558..a28b1db0 100644 --- a/explorer/forms.py +++ b/explorer/forms.py @@ -41,7 +41,8 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields["database_connection"].widget.choices = self.connections if not self.instance.database_connection: - self.initial["database_connection"] = default_db_connection().alias + default_db = default_db_connection() + self.initial["database_connection"] = default_db_connection().alias if default_db else None self.fields["database_connection"].widget.attrs["class"] = "form-select" def clean(self): @@ -66,6 +67,10 @@ def created_at_time(self): @property def connections(self): + default_db = default_db_connection() + if default_db is None: + return [] + # Ensure the default connection appears first in the dropdown in the form result = DatabaseConnection.objects.annotate( custom_order=Case( diff --git a/explorer/templates/explorer/base.html b/explorer/templates/explorer/base.html index 32bac5ba..1b4023c4 100644 --- a/explorer/templates/explorer/base.html +++ b/explorer/templates/explorer/base.html @@ -80,6 +80,12 @@

This is easy to fix, I promise!

{% translate "Favorites" %} + {% if hosted %} + + {% endif %} diff --git a/explorer/templates/explorer/play.html b/explorer/templates/explorer/play.html index eb3935c0..ded60a33 100644 --- a/explorer/templates/explorer/play.html +++ b/explorer/templates/explorer/play.html @@ -16,7 +16,7 @@

{% translate "Playground" %}

{{ error|escape }}
{% endif %} {{ form.non_field_errors }} - {% if form.connections|length > 1 and can_change %} + {% if can_change %}
{{ form.database_connection }} @@ -26,7 +26,6 @@

{% translate "Playground" %}

{{ form.database_connection }}
-
{{ form.database_connection.value }}
{% endif %}
diff --git a/explorer/templates/explorer/query.html b/explorer/templates/explorer/query.html index ce640aba..dc85da46 100644 --- a/explorer/templates/explorer/query.html +++ b/explorer/templates/explorer/query.html @@ -39,7 +39,7 @@

{{ error|escape }}
{% endfor %}{% endif %}

- {% if form.connections|length > 1 and can_change %} + {% if can_change %}
{{ form.database_connection }} diff --git a/explorer/templates/explorer/query_list.html b/explorer/templates/explorer/query_list.html index 9bd321ca..2ea415ad 100644 --- a/explorer/templates/explorer/query_list.html +++ b/explorer/templates/explorer/query_list.html @@ -3,160 +3,171 @@ {% block sql_explorer_content %}
{% csrf_token %}
- {% if recent_queries|length > 0 %} + {% if connection_count == 0 %}
-

{% translate "Recently Run by You" %}

+

+ Welcome! +

+

+ Create a connection to get started +

+
+ {% else %} + {% if recent_queries|length > 0 %} +
+

{% translate "Recently Run by You" %}

+ + + + + + + + + + {% for object in recent_queries %} + + + + + + {% endfor %} + +
{% translate "Query" %}{% translate "Last Run" %}CSV
+ {{ object.query.title }} + {{ object.run_at|date:"SHORT_DATETIME_FORMAT" }} + + + +
+
+ {% endif %} + +
+
+
+

{% translate "All Queries" %}

+
+
+ +
+
- - - + + + {% if tasks_enabled %} + + {% endif %} + + {% if can_change %} + + + {% endif %} + + + + - - {% for object in recent_queries %} - - - - - - {% endfor %} - -
{% translate "Query" %}{% translate "Last Run" %}CSV{% translate "Query" %}{% translate "Created" %}{% translate "Email" %}{% translate "CSV" %}{% translate "Play" %}{% translate "Delete" %}{% translate "Favorite" %}{% translate "Last Run" %}{% translate "Run Count" %}{% translate "Connection" %}
- {{ object.query.title }} - {{ object.run_at|date:"SHORT_DATETIME_FORMAT" }} - - - -
-
- {% endif %} - -
-
-
-

{% translate "All Queries" %}

-
-
- -
-
- - - - - - {% if tasks_enabled %} - - {% endif %} - - {% if can_change %} - - - {% endif %} - - - - - - - - {% for object in object_list %} - - {% if object.is_header %} - - {% else %} - - + {% for object in object_list %} + + {% if object.is_header %} + + {% else %} + + + {% if tasks_enabled %} + {% endif %} - - {% if tasks_enabled %} - - {% endif %} - - {% if can_change %} - + + {% endif %} + + + + {% endif %} - - - - - {% endif %} - - {% endfor %} - -
{% translate "Query" %}{% translate "Created" %}{% translate "Email" %}{% translate "CSV" %}{% translate "Play" %}{% translate "Delete" %}{% translate "Favorite" %}{% translate "Last Run" %}{% translate "Run Count" %}{% translate "Connection" %}
- - - {{ object.title }} ({{ object.count }}) - - - - {{ object.title }} - {{ object.created_at|date:"m/d/y" }} - {% if object.created_by_user %} - {% blocktranslate trimmed with cuser=object.created_by_user %} - by {{cuser}} - {% endblocktranslate %} +
+ + + {{ object.title }} ({{ object.count }}) + + + + {{ object.title }} + {{ object.created_at|date:"m/d/y" }} + {% if object.created_by_user %} + {% blocktranslate trimmed with cuser=object.created_by_user %} + by {{cuser}} + {% endblocktranslate %} + {% endif %} + + + - - - - - - - - + + - - - + {% if can_change %} + + + + + + + + + {% query_favorite_button object.id object.is_favorite 'query_favorite_toggle' %}{% if object.ran_successfully %} + + {% elif object.ran_successfully is not None %} + + {% endif %} + {{ object.last_run_at|date:"m/d/y" }} {{ object.run_count }}{{ object.connection_name }} {% query_favorite_button object.id object.is_favorite 'query_favorite_toggle' %}{% if object.ran_successfully %} - - {% elif object.ran_successfully is not None %} - - {% endif %} - {{ object.last_run_at|date:"m/d/y" }} - {{ object.run_count }}{{ object.connection_name }}
-
+ + {% endfor %} + + +
-