From dd79662c1b0e23191a8e0a17a55c5e045ec316ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 8 Aug 2022 18:57:30 +0200 Subject: [PATCH] fields: use accessor to get prefill configuration (#67843) This allows an uniform handling of the unexpected {'type': 'none'} situation. --- wcs/fields.py | 12 +++++++++--- wcs/formdata.py | 6 +++--- wcs/forms/common.py | 6 +++--- wcs/forms/root.py | 16 +++++++--------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/wcs/fields.py b/wcs/fields.py index 218d27a37..7695d1dd2 100644 --- a/wcs/fields.py +++ b/wcs/fields.py @@ -486,6 +486,12 @@ class Field: return None return data.get('%s_structured' % self.id) + def get_prefill_configuration(self): + if self.prefill and self.prefill.get('type') == 'none': + # make sure a 'none' prefill is not considered as a value + self.prefill = None + return self.prefill or {} + def get_prefill_value(self, user=None, force_string=True): # returns a tuple with two items, # 1. value[str], the value that will be used to prefill @@ -564,7 +570,7 @@ class Field: return (None, False) def get_prefill_attributes(self): - if not self.prefill: + if not self.get_prefill_configuration(): return t = self.prefill.get('type') @@ -747,8 +753,8 @@ class Field: return str(value) def get_prefill_parameter_view_value(self, widget): - value = getattr(self, 'prefill', None) - if not value or value.get('type') == 'none': + value = self.get_prefill_configuration() + if not value: return r = TemplateIO(html=True) r += htmltext('