From d1320c4ed21f43c29fbce7721e8e55ad1305eca1 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Sat, 23 Jan 2021 15:32:54 -0600 Subject: [PATCH] Add a "null" setting to control upload of NULL values --- src/pgwui_upload_core/check_settings.py | 4 ++- src/pgwui_upload_core/template_utils.py | 31 ++++++++++++++++++++++ src/pgwui_upload_core/templates/upload.mak | 5 +--- src/pgwui_upload_core/views/upload.py | 14 +++++++--- 4 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 src/pgwui_upload_core/template_utils.py diff --git a/src/pgwui_upload_core/check_settings.py b/src/pgwui_upload_core/check_settings.py index 7787709..04eb1a2 100644 --- a/src/pgwui_upload_core/check_settings.py +++ b/src/pgwui_upload_core/check_settings.py @@ -25,11 +25,13 @@ from pgwui_common import checkset UPLOAD_SETTINGS = ['menu_label', 'literal_column_headings', 'trim', + 'null', ] REQUIRED_SETTINGS = [] BOOLEAN_SETTINGS = [] BOOLEAN_CHOICE_SETTINGS = ['literal_column_headings', - 'trim'] + 'trim', + 'null'] def check_settings( diff --git a/src/pgwui_upload_core/template_utils.py b/src/pgwui_upload_core/template_utils.py new file mode 100644 index 0000000..107eda7 --- /dev/null +++ b/src/pgwui_upload_core/template_utils.py @@ -0,0 +1,31 @@ +# Copyright (C) 2021 The Meme Factory, Inc. http://www.karlpinc.com/ + +# This file is part of Pgwui_Upload_Core. +# +# 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 +# . +# + +# Karl O. Pinc + +'''Utility functions used in templates +''' + + +def show_choice(pgwui, setting): + '''Interpret a boolean_choice setting; should the user interface + display something? + ''' + val = pgwui['upload_settings'][setting] + return (val == 'choice-yes' or val == 'choice-no') diff --git a/src/pgwui_upload_core/templates/upload.mak b/src/pgwui_upload_core/templates/upload.mak index b085546..4b97dc6 100644 --- a/src/pgwui_upload_core/templates/upload.mak +++ b/src/pgwui_upload_core/templates/upload.mak @@ -34,13 +34,10 @@ <%! + from pgwui_upload_core.template_utils import show_choice from pgwui_common.path import asset_abspath auth_base_mak = asset_abspath('pgwui_common:templates/auth_base.mak') - - def show_choice(pgwui, setting): - val = pgwui['upload_settings'][setting] - return (val == 'choice-yes' or val == 'choice-no') %> <%inherit file="${auth_base_mak}" /> diff --git a/src/pgwui_upload_core/views/upload.py b/src/pgwui_upload_core/views/upload.py index da14646..7dbab4e 100644 --- a/src/pgwui_upload_core/views/upload.py +++ b/src/pgwui_upload_core/views/upload.py @@ -56,13 +56,19 @@ class UploadCoreInitialPost(UploadNullFileInitialPost): self.component = component return self + def boolean_choice(self, upload_settings, setting): + val = upload_settings[setting] + # Technically, we only need 'choice-yes' here because + # otherwise the result is never displayed on the page. + return (val == 'yes-always' or val == 'choice-yes') + def build(self, settings={}): super().build(settings) upload_settings = settings['pgwui'][self.component] - self.trim_upload = ( - upload_settings['trim'] == 'choice-yes') - lch = upload_settings['literal_column_headings'] - self.literal_col_headings = (lch == 'yes-always', 'choice-yes') + self.upload_null = self.boolean_choice(upload_settings, 'null') + self.trim_upload = self.boolean_choice(upload_settings, 'trim') + self.literal_col_headings = self.boolean_choice( + upload_settings, 'literal_column_headings') return self -- 2.34.1