From 7b0005787474cdb4ee9b5d3d91e22e83e44cb484 Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Tue, 13 Aug 2024 10:52:54 -0400 Subject: [PATCH] forms working --- explorer/forms.py | 10 +++++----- explorer/src/js/codemirror-config.js | 2 +- explorer/src/js/schemaService.js | 2 +- explorer/templates/explorer/query.html | 4 ++-- explorer/tests/test_views.py | 10 +++++----- explorer/urls.py | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/explorer/forms.py b/explorer/forms.py index 375877f0..aa9acf6d 100644 --- a/explorer/forms.py +++ b/explorer/forms.py @@ -33,14 +33,14 @@ class QueryForm(ModelForm): sql = SqlField() snapshot = BooleanField(widget=CheckboxInput, required=False) - connection = CharField(widget=Select, required=False) + database_connection = CharField(widget=Select, required=False) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.fields["connection"].widget.choices = self.connections + self.fields["database_connection"].widget.choices = self.connections if not self.instance.database_connection: self.initial["database_connection"] = EXPLORER_DEFAULT_CONNECTION - self.fields["connection"].widget.attrs["class"] = "form-select" + self.fields["database_connection"].widget.attrs["class"] = "form-select" def clean(self): # Don't overwrite created_by_user @@ -55,8 +55,8 @@ def created_at_time(self): @property def connections(self): - return [(c.alias, c.id) for c in DatabaseConnection.objects.all()] + return [(c.id, c.alias) for c in DatabaseConnection.objects.all()] class Meta: model = Query - fields = ["title", "sql", "description", "snapshot", "connection"] + fields = ["title", "sql", "description", "snapshot", "database_connection"] diff --git a/explorer/src/js/codemirror-config.js b/explorer/src/js/codemirror-config.js index 4343eb9c..a4539e49 100644 --- a/explorer/src/js/codemirror-config.js +++ b/explorer/src/js/codemirror-config.js @@ -55,7 +55,7 @@ function fetchAndShowSchema(view) { if (schema.hasOwnProperty(tableName)) { formattedSchema = JSON.stringify(schema[tableName], null, 2); } else { - formattedSchema = `Table '${tableName}' not found in schema for connection '${conn}'`; + formattedSchema = `Table '${tableName}' not found in schema for connection`; } displaySchemaTooltip(view, formattedSchema); }); diff --git a/explorer/src/js/schemaService.js b/explorer/src/js/schemaService.js index 7f5e49bf..84e9e577 100644 --- a/explorer/src/js/schemaService.js +++ b/explorer/src/js/schemaService.js @@ -27,5 +27,5 @@ export const SchemaSvc = { }; export function getConnElement() { - return document.querySelector('#id_connection'); + return document.querySelector('#id_database_connection'); } diff --git a/explorer/templates/explorer/query.html b/explorer/templates/explorer/query.html index af8ab0ae..8319e599 100644 --- a/explorer/templates/explorer/query.html +++ b/explorer/templates/explorer/query.html @@ -41,8 +41,8 @@

{% if form.connections|length > 1 and can_change %}
- {{ form.connection }} - + {{ form.database_connection }} +
{% else %} {# still need to submit the connection, just hide the UI element #} diff --git a/explorer/tests/test_views.py b/explorer/tests/test_views.py index 3024782d..4f2b05b2 100644 --- a/explorer/tests/test_views.py +++ b/explorer/tests/test_views.py @@ -21,7 +21,7 @@ from explorer.models import MSG_FAILED_BLACKLIST, Query, QueryFavorite, QueryLog, DatabaseConnection from explorer.tests.factories import QueryLogFactory, SimpleQueryFactory from explorer.utils import user_can_see_query -from explorer.ee.db_connections.utils import default_db_connection_id +from explorer.ee.db_connections.utils import default_db_connection def reload_app_settings(): @@ -652,28 +652,28 @@ def setUp(self): def test_returns_schema_contents(self): resp = self.client.get( - reverse("explorer_schema", kwargs={"connection": default_db_connection_id()}) + reverse("explorer_schema", kwargs={"connection": default_db_connection().alias}) ) self.assertContains(resp, "explorer_query") self.assertTemplateUsed(resp, "explorer/schema.html") def test_returns_schema_contents_json(self): resp = self.client.get( - reverse("explorer_schema_json", kwargs={"connection": default_db_connection_id()}) + reverse("explorer_schema_json", kwargs={"connection": default_db_connection().alias}) ) self.assertContains(resp, "explorer_query") self.assertEqual(resp.headers["Content-Type"], "application/json") def test_returns_404_if_conn_doesnt_exist(self): resp = self.client.get( - reverse("explorer_schema", kwargs={"connection": 4}) + reverse("explorer_schema", kwargs={"connection": "bananas"}) ) self.assertEqual(resp.status_code, 404) def test_admin_required(self): self.client.logout() resp = self.client.get( - reverse("explorer_schema", kwargs={"connection": 1}) + reverse("explorer_schema", kwargs={"connection": default_db_connection().alias}) ) self.assertTemplateUsed(resp, "admin/login.html") diff --git a/explorer/urls.py b/explorer/urls.py index ef8a3080..36fec7bb 100644 --- a/explorer/urls.py +++ b/explorer/urls.py @@ -31,11 +31,11 @@ path("new/", CreateQueryView.as_view(), name="query_create"), path("play/", PlayQueryView.as_view(), name="explorer_playground"), path( - "schema/", SchemaView.as_view(), + "schema/", SchemaView.as_view(), name="explorer_schema" ), path( - "schema.json/", SchemaJsonView.as_view(), + "schema.json/", SchemaJsonView.as_view(), name="explorer_schema_json" ), path("logs/", ListQueryLogView.as_view(), name="explorer_logs"),