Add a "null" setting to control upload of NULL values
authorKarl O. Pinc <kop@karlpinc.com>
Sat, 23 Jan 2021 21:32:54 +0000 (15:32 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Sat, 23 Jan 2021 21:33:52 +0000 (15:33 -0600)
src/pgwui_upload_core/check_settings.py
src/pgwui_upload_core/template_utils.py [new file with mode: 0644]
src/pgwui_upload_core/templates/upload.mak
src/pgwui_upload_core/views/upload.py

index 778770925f5b427f8538509f646b6e085b9c0b07..04eb1a227ffdd0be14271daf261d22ffc7af8834 100644 (file)
@@ -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 (file)
index 0000000..107eda7
--- /dev/null
@@ -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
+# <http://www.gnu.org/licenses/>.
+#
+
+# Karl O. Pinc <kop@karlpinc.com>
+
+'''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')
index b0855464ee7fa7aeb0c5b3bc413765eb98fc65ff..4b97dc6ac7247a8e158c499335cad8e22c066566 100644 (file)
 
 
 <%!
+    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}" />
index da146467fa5bc534d80c3c5456930e80895bf2dc..7dbab4eaafae95c2d55976793a5e5b15d14effb9 100644 (file)
@@ -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