From 5b1fa3c9a7982065c720a20d1528d85b7907e3ea Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Tue, 30 Jul 2024 18:25:52 -0500 Subject: [PATCH] Split out single-db using forms into a separate template Uses "main_form". The inheriting template always initiates execution. Move upload fields into pgwui_upload_core. --- src/pgwui_common/templates/auth_base.mak | 107 +---------------------- src/pgwui_common/templates/db_base.mak | 89 +++++++++++++++++++ 2 files changed, 93 insertions(+), 103 deletions(-) create mode 100644 src/pgwui_common/templates/db_base.mak diff --git a/src/pgwui_common/templates/auth_base.mak b/src/pgwui_common/templates/auth_base.mak index 8d4fafe..633a1fb 100644 --- a/src/pgwui_common/templates/auth_base.mak +++ b/src/pgwui_common/templates/auth_base.mak @@ -19,7 +19,7 @@ License along with this program. If not, see . - Base template for form that authenticates a user and accesses a db. + Base template for form that authenticates a user. Karl O. Pinc @@ -87,103 +87,7 @@ table. -<%def name="database_row(tab_index)"> - - - - - - - - - <% tab_index.inc() %> - - -<%def name="format_row(tab_index)"> - - Uploaded Data Format: - - - -
- - - - - <% tab_index.inc(2) %> - - -<%def name="nulls_row(tab_index)"> - % if show_choice(pgwui, 'null'): - - - - - - - - - - - - - - - - - <% tab_index.inc(2) %> - % endif - - -<%def name="file_row(tab_index)"> - - - - - - - - - <% tab_index.inc() %> - - -<%def name="upload_form(upload_nulls=True)"> +<%def name="main_form(tab_index)">
${self.auth_parts.hidden_vars(csrf_token)} @@ -197,16 +101,13 @@ <% - tab_index = TabIndex() - database_row(tab_index) + if hasattr(caller, 'database_row'): + caller.database_row(tab_index) self.auth_parts.user_row(tab_index, havecreds, user) self.auth_parts.password_row(tab_index, havecreds) caller.body(tab_index) - format_row(tab_index) - nulls_row(tab_index) - file_row(tab_index) %>
diff --git a/src/pgwui_common/templates/db_base.mak b/src/pgwui_common/templates/db_base.mak new file mode 100644 index 0000000..80b2775 --- /dev/null +++ b/src/pgwui_common/templates/db_base.mak @@ -0,0 +1,89 @@ + +<%doc> + Copyright (C) 2024 The Meme Factory, Inc. http://www.karlpinc.com/ + + This file is part of PGWUI_Common. + + 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 + . + + Base template for form that authenticates a user and accesses a db. + + Karl O. Pinc + + This template uses the following variables in it's context: + havecreds Already logged in + errors A list of UploadError exceptions. + lines (Optional) Number of lines in uploaded file. + When omitted, there's no "uploaded file". + filename (Optional) Name of uploaded file. + filepath (Optional) Path of uploaded file. + relation (Optional) Table or view uploaded into. + e_cnt (Optional) Number of errors to display. + + For use with upload_form: + csrf_token Token for detecting CSRF. + report_success Boolean. Whether to tell the user the db was changed. + db_changed Boolean. Whether the previous upload changed db content. + Different from report_success because "previous upload" + ignores session expiration. (Unlike report_success, + db_changed is a form variable, not a session variable.) + session_expired Boolean. Whether the session has expired. + last_key Token to detect duplicate uploads. + db + user + csv_value + tab_value + tab_checked + csv_checked + upload_null + null_rep + + +<%! + from pgwui_common.path import asset_abspath + + auth_base_mak = asset_abspath('pgwui_common:templates/auth_base.mak') +%> + +<%inherit file="${auth_base_mak}" /> + +<%doc> All the *_row() defs take a tab_index and, as a side effect, + increment the tab_index with the number of rows added to the + table. + + +<%def name="main_form(tab_index)"> + <%parent:main_form tab_index="${tab_index}" args="tab_index"> + <%def name="database_row(tab_index)"> + + + + + + + + + <% tab_index.inc() %> + + + <% caller.body(tab_index) %> + + -- 2.34.1