<%block name="top_hr">
</%block>
+<script>
+ function show_search_path() {
+ fetch('${request.route_path("pgwui_sql_db_search_path")|n}')
+ .then((response) => {
+ if (!response.ok) {
+ window.alert('Problem obtaining the search_path');
+ }
+ return response.text();
+ })
+ .then((search_path) => {
+ const sp_elemt = document.getElementById('search_path_id');
+ sp_elemt.value = search_path;
+ })
+ .catch((error) => {
+ window.alert('Problem showing the search_path: ' + error);
+ })
+ };
+</script>
+
<%def name="sql_row(tab_index)">
<tr>
<%self.lib:td_label for_id="search_path_id">
value="${search_path}"
/>
</%self.lib:td_input>
+ <td>
+ <button type="button" tabindex="${tab_index.val}"
+ onclick="show_search_path();"
+ >Reset</button>
+ <% tab_index.inc() %>
+ </td>
</tr>
<tr>
- <%self.lib:td_input tab_index="${tab_index}" colspan="2">
+ <%self.lib:td_input tab_index="${tab_index}" colspan="3">
<textarea name="sql"
class="sqltext"
tabindex="${tab_index.val}"
--- /dev/null
+# Copyright (C) 2024 The Meme Factory, Inc. http://www.karlpinc.com/
+
+# This file is part of PGWUI_SQL.
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/>.
+#
+
+from pyramid.view import view_config
+import logging
+import pgwui_core.core
+import pgwui_core.forms
+import pgwui_sql.views.base
+import pgwui_sql.views.search_path_base
+
+log = logging.getLogger(__name__)
+
+
+@view_config(route_name='pgwui_sql_db_search_path',
+ renderer='string')
+def sql_edit_view(request):
+ # This can use the UnsafeUploadEngine because it does not alter
+ # server state. We are not getting any form data from the user.
+ # We don't have access to the CSRF token because the page is not
+ # sent a POST request.
+
+ uh = pgwui_sql.views.search_path_base.SQLEditHandler(request).init()
+ response, errors = pgwui_core.core.UnsafeUploadEngine(uh).run()
+ if errors:
+ log.warning(f'Failed to get search_path: ({errors})')
+
+ if uh.data is None:
+ log.debug('search_path requested when user not logged in: DB {db}:'
+ # ' File ({filename}):'
+ # ' Format {format}:'
+ ' By user {user}:'
+ .format( # filename=response['filename'],
+ # format=download_fmt,
+ db=response['db'],
+ user=response['user']))
+ search_path = ''
+ else:
+ # The hander executed; the user is logged in
+ search_path = uh.data.stmts[0].result
+
+ # if pgwui_core.utils.is_checked(response['csv_checked']):
+ # download_fmt = 'CSV'
+ # else:
+ # download_fmt = 'TAB'
+ log.debug('Successful sql editor request: DB {db}:'
+ # ' File ({filename}):'
+ # ' Format {format}:'
+ ' By user {user}:'
+ ' search_path ({search_path})'
+ .format( # filename=response['filename'],
+ # format=download_fmt,
+ db=response['db'],
+ user=response['user'],
+ search_path=search_path))
+
+ return search_path