Fix double-upload test by handling boolean post values
authorKarl O. Pinc <kop@karlpinc.com>
Mon, 5 Aug 2024 16:59:54 +0000 (11:59 -0500)
committerKarl O. Pinc <kop@karlpinc.com>
Mon, 5 Aug 2024 16:59:54 +0000 (11:59 -0500)
src/pgwui_core/core.py

index b2f720a37802a0fa8049d33d0009cedd16171c9d..499d29ae3bffdec4e65e2d48ae7b69485b898707 100644 (file)
@@ -209,6 +209,16 @@ class LoadedForm(collections.abc.MutableMapping):
     def __delitem__(self, key):
         del self._store[key]
 
+    def booleanize_post(self, post, key):
+        '''The key, if present, is a boolean value.  But post data
+        is all strings.  Convert the post data to a Python boolean.
+        '''
+        if key in post:
+            if post[key] == 'False':
+                post[key] = False
+            else:
+                post[key] = True
+
     def read_post_and_session(self, post, session, key):
         '''Read an attribute into self, from either POST or the session,
         and synchronize the session with the POST value when there is a POST
@@ -440,6 +450,7 @@ class UploadFileForm(AuthLoadedForm):
         # Other POST variables involving a file
         post = self.uh.request.POST
         session = self.uh.request.session
+        self.booleanize_post(post, 'db_changed')
         if not self.read_post_and_session(post, session, 'db_changed'):
             self['db_changed'] = False
         self['filename'] = ''