-# Copyright (C) 2018, 2020, 2021 The Meme Factory, Inc.
+# Copyright (C) 2018, 2020, 2021, 2024 The Meme Factory, Inc.
# http://www.karlpinc.com/
# This file is part of PGWUI_SQL
f'{PGWUI_COMPONENT}:static/',
cache_max_age=3600)
config.add_route(PGWUI_COMPONENT, DEFAULT_SQL_ROUTE)
+ config.add_route('pgwui_sql_edit', '/sql_edit')
config.scan()
This template uses the following variables in it's context:
+ sql Text of the sql command(s)
result_rows List of SQLResult objects
</%doc>
<%!
from pgwui_common.path import asset_abspath
- db_base_mak = asset_abspath('pgwui_common:templates/db_base.mak')
+ sql_base_mak = asset_abspath('pgwui_sql:templates/sql_base.mak')
%>
-<%inherit file="${db_base_mak}" />
-
-<%block name="title">${pgwui['pgwui_sql']['menu_label']}</%block>
-<%block name="meta_keywords">
- <meta name="keywords"
- content="PGWUI SQL" />
-</%block>
-
-<%block name="meta_description">
- <meta name="description"
- content="PostgreSQL Web User Interface, Interactive SQL execution" />
-</%block>
-
-<%block name="stylesheet_links">
- ${parent.stylesheet_links()}
- <link rel="stylesheet"
- href="${request.static_url('pgwui_sql:static/pgwui_sql.css')}"
- type="text/css" />
-</%block>
+<%inherit file="${sql_base_mak}" />
<%block name="action_success">
<p><em class="success">Executed SQL without errors</em>,
Execute SQL
</%block>
-<%def name="sql_row(tab_index)">
- <tr>
- <%self.lib:td_label for_id="sql_id">SQL</%self.lib:td_label>
- </tr>
- <tr>
- <%self.lib:td_input tab_index="${tab_index}" colspan="2">
- <textarea name="sql"
- class="sqltext"
- tabindex="${tab_index.val}"
- id="sql_id">${sql}</textarea>
- </%self.lib:td_input>
- </tr>
-</%def>
-
-<%def name="submit(tab_index)">
- <input value="Execute" tabindex="${tab_index.val}" type="submit" />
- <% tab_index.inc() %>
-</%def>
-
-<%def name="table_rows(tab_index)">
- <%parent:table_rows tab_index="${tab_index}" args="tab_index">
- ## A blank table row for spacing
- <tr class="verticalgap"><td/><td/></tr>
- ${sql_row(tab_index)}
- </%parent:table_rows>
-</%def>
-
<%def name="render_heading(headings)">
<% if headings is None:
return STOP_RENDERING
</form>
</%def>
+<script>
+ window.name='${self.sql_results_target()}';
+</script>
+
<% tab_index = self.attr.TabIndex() %>
% if result_rows:
${render_results()}
--- /dev/null
+<%doc>
+ 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/>.
+
+ Template used by sql pages.
+
+ Karl O. Pinc <kop@karlpinc.com>
+
+ This template uses the following variables in it's context:
+
+ sql Text of the sql command(s)
+</%doc>
+
+
+<%!
+ from pgwui_common.path import asset_abspath
+
+ db_base_mak = asset_abspath('pgwui_common:templates/db_base.mak')
+%>
+
+<%inherit file="${db_base_mak}" />
+
+<%def name="sql_results_target()" buffered="True" filter='trim'>
+ ${f'sql_results:{request.host}:{db}:{user}'}
+</%def>
+
+<%block name="title">${pgwui['pgwui_sql']['menu_label']}</%block>
+<%block name="meta_keywords">
+ <meta name="keywords"
+ content="PGWUI SQL" />
+</%block>
+
+<%block name="meta_description">
+ <meta name="description"
+ content="PostgreSQL Web User Interface, Interactive SQL execution" />
+</%block>
+
+<%block name="stylesheet_links">
+ ${parent.stylesheet_links()}
+ <link rel="stylesheet"
+ href="${request.static_url('pgwui_sql:static/pgwui_sql.css')}"
+ type="text/css" />
+</%block>
+
+<%def name="submit(tab_index)">
+ <input value="Execute" tabindex="${tab_index.val}" type="submit" />
+ <% tab_index.inc() %>
+</%def>
+
+<%def name="sql_row(tab_index)">
+ <tr>
+ <%self.lib:td_label for_id="sql_id">SQL</%self.lib:td_label>
+ <td><button type="button" tabindex="${tab_index.val}"
+ onclick="window.open(
+ '${request.route_path("pgwui_sql_edit")|n}',
+ 'sql_edit',
+ 'popup=true,width=800,height=600')"
+ >Show In Window</button></td>
+ <% tab_index.inc() %>
+ </tr>
+ <tr>
+ <%self.lib:td_input tab_index="${tab_index}" colspan="2">
+ <textarea name="sql"
+ class="sqltext"
+ tabindex="${tab_index.val}"
+ id="sql_id">${sql}</textarea>
+ </%self.lib:td_input>
+ </tr>
+</%def>
+
+<%def name="table_rows(tab_index)">
+ <%parent:table_rows tab_index="${tab_index}" args="tab_index">
+ ## A blank table row for spacing
+ <tr class="verticalgap"><td/><td/></tr>
+ ${sql_row(tab_index)}
+ </%parent:table_rows>
+</%def>
+
+<%block name="hidden_vars">
+ <%parent:hidden_vars>
+ <input type="hidden"
+ name="db"
+ value="${db}"
+ />
+ <input type="hidden"
+ name="user"
+ value="${user}"
+ />
+ </%parent:hidden_vars>
+</%block>
--- /dev/null
+<%doc>
+ 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/>.
+
+ Template for sql command entry page.
+
+ Karl O. Pinc <kop@karlpinc.com>
+
+ This template uses the following variables in it's context:
+
+ sql Text of the sql command(s)
+</%doc>
+
+
+<%!
+ from pgwui_common.path import asset_abspath
+
+ sql_base_mak = asset_abspath('pgwui_sql:templates/sql_base.mak')
+%>
+
+<%inherit file="${sql_base_mak}" />
+
+<%block name="page_heading">
+ SQL Entry Window
+</%block>
+
+<% tab_index = self.attr.TabIndex() %>
+${self.main_form(tab_index, target=self.sql_results_target(),
+ action=request.route_path('pgwui_sql'))}
db=response['db'],
user=response['user']))
return response
+
+
+@view_config(route_name='pgwui_sql_edit',
+ renderer='pgwui_sql:templates/sql_edit.mak')
+@auth_base_view
+def sql_edit_view(request):
+
+ uh = SQLHandler(request).init()
+ response = pgwui_core.core.UploadEngine(uh).run()
+
+ settings = request.registry.settings
+ response.setdefault('pgwui', dict())
+ response['pgwui']['pgwui_sql'] = settings['pgwui']['pgwui_sql']
+
+ response['result_rows'] = uh.sql_results
+
+ if response['report_success']:
+ # if pgwui_core.utils.is_checked(response['csv_checked']):
+ # download_fmt = 'CSV'
+ # else:
+ # download_fmt = 'TAB'
+ log.info('Successful sql: DB {db}:'
+ # ' File ({filename}):'
+ # ' Format {format}:'
+ ' By user {user}'
+ .format( # filename=response['filename'],
+ # format=download_fmt,
+ db=response['db'],
+ user=response['user']))
+ return response
mock_establish_settings.assert_called_once()
mocked_add_static_view.assert_called_once()
- mocked_add_route.assert_called_once()
+ assert mocked_add_route.call_count == 2
mocked_scan.assert_called_once()