From: Karl O. Pinc Date: Mon, 5 Aug 2024 16:59:54 +0000 (-0500) Subject: Fix double-upload test by handling boolean post values X-Git-Url: https://papio.biology.duke.edu/gitweb/?a=commitdiff_plain;h=8e039ed3a18e88d345343c8ddc0b97dcf7e09721;p=pgwui_core Fix double-upload test by handling boolean post values --- diff --git a/src/pgwui_core/core.py b/src/pgwui_core/core.py index b2f720a..499d29a 100644 --- a/src/pgwui_core/core.py +++ b/src/pgwui_core/core.py @@ -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'] = ''