From 3bb10e9204157e8ae935a2cc415337e096269756 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Thu, 29 Apr 2021 22:57:06 -0500 Subject: [PATCH] Abstract out common auth form elements --- src/pgwui_common/templates/auth_base.mak | 53 +++------------ src/pgwui_common/templates/auth_parts.mak | 79 +++++++++++++++++++++++ 2 files changed, 88 insertions(+), 44 deletions(-) create mode 100644 src/pgwui_common/templates/auth_parts.mak diff --git a/src/pgwui_common/templates/auth_base.mak b/src/pgwui_common/templates/auth_base.mak index bb7f0be..ca76372 100644 --- a/src/pgwui_common/templates/auth_base.mak +++ b/src/pgwui_common/templates/auth_base.mak @@ -24,6 +24,7 @@ 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". @@ -51,21 +52,18 @@ from pgwui_common.path import asset_abspath errors_base_mak = asset_abspath('pgwui_common:templates/errors_base.mak') + auth_parts_mak = asset_abspath('pgwui_common:templates/auth_parts.mak') %> <%inherit file="${errors_base_mak}" /> +<%namespace file="${auth_parts_mak}" + name="auth_parts" + inheritable="True" /> <%def name="upload_form(extra_rows=[], upload_nulls=True)">
- - + ${self.auth_parts.hidden_vars(csrf_token)} % if (db_changed or session_expired) and last_key: - - - - - - % if havecreds: - ${user} - % else: - - % endif - - - % if not havecreds: - - - - - - - - - % endif + ${self.auth_parts.user_row(2, havecreds, user)} + <% tab_index = 3 %> + ${self.auth_parts.password_row(tab_index, havecreds)} - <% - tab_index = 3 - %> % for row in extra_rows: <% tab_index += 1 diff --git a/src/pgwui_common/templates/auth_parts.mak b/src/pgwui_common/templates/auth_parts.mak new file mode 100644 index 0000000..12d77ab --- /dev/null +++ b/src/pgwui_common/templates/auth_parts.mak @@ -0,0 +1,79 @@ + +<%doc> + Copyright (C) 2015, 2020, 2021 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 + user + + +<%def name="hidden_vars(csrf_token)"> + + + + +<%def name="user_row(tabindex, havecreds, user)"> + + + + + + % if havecreds: + ${user} + % else: + + % endif + + + + +<%def name="password_row(tabindex, havecreds)"> + % if not havecreds: + + + + + + + + + % endif + -- 2.34.1