diff --git a/opentech/apply/categories/blocks.py b/opentech/apply/categories/blocks.py index 0d3be36bfa355fbaf5699cedd38f53725b830a11..5a0c5cf11c20bea90e7aa9c9e37a1178755059a7 100644 --- a/opentech/apply/categories/blocks.py +++ b/opentech/apply/categories/blocks.py @@ -72,3 +72,6 @@ class CategoryQuestionBlock(OptionalFormFieldBlock): category = value['category'] context['data'] = category.options.filter(id__in=data).values_list('value', flat=True) return super().render(value, context) + + def get_searchable_content(self, value, data): + return None diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py index 869009607628d3f500e8fa7e852367eb330d1f04..5b5a3535e8312ccfd4490b59a19924066aee74b2 100644 --- a/opentech/apply/funds/models.py +++ b/opentech/apply/funds/models.py @@ -508,10 +508,9 @@ class ApplicationSubmission(WorkflowHelpers, AbstractFormSubmission): return mark_safe(''.join(fields)) def prepare_search_values(self): - excluded_fields = ['data', 'time', 'datetime', 'value', 'category', 'number', 'file', 'multifile'] for data, stream in self.data_and_fields(): - if stream.block_type not in excluded_fields and data: - value = stream.block.get_searchable_content(stream.value, data) + value = stream.block.get_searchable_content(stream.value, data) + if value: if isinstance(value, list): yield ', '.join(value) else: diff --git a/opentech/apply/stream_forms/blocks.py b/opentech/apply/stream_forms/blocks.py index 94fa52a9643d7eca72fa0edd6ff747dd4fe6ccfe..aaf6b4fe8ceffef9b0fc47f4f2e335744d3e24de 100644 --- a/opentech/apply/stream_forms/blocks.py +++ b/opentech/apply/stream_forms/blocks.py @@ -55,6 +55,9 @@ class FormFieldBlock(StructBlock): class OptionalFormFieldBlock(FormFieldBlock): required = BooleanBlock(label=_('Required'), required=False) + def get_searchable_content(self, value, data): + return data + CHARFIELD_FORMATS = [ ('email', _('Email')), @@ -79,6 +82,8 @@ class CharFieldBlock(OptionalFormFieldBlock): return super().get_field_class(struct_value) def get_searchable_content(self, value, data): + # CharField acts as a fallback. Force data to string + data = str(data) return bleach.clean(data, tags=[], strip=True) @@ -103,6 +108,9 @@ class NumberFieldBlock(OptionalFormFieldBlock): class Meta: label = _('Number field') + def get_searchable_content(self, value, data): + return None + class CheckboxFieldBlock(FormFieldBlock): default_value = BooleanBlock(required=False) @@ -113,6 +121,9 @@ class CheckboxFieldBlock(FormFieldBlock): label = _('Checkbox field') icon = 'tick-inverse' + def get_searchable_content(self, value, data): + return None + class RadioButtonsFieldBlock(OptionalFormFieldBlock): choices = ListBlock(CharBlock(label=_('Choice'))) @@ -191,6 +202,9 @@ class DateFieldBlock(OptionalFormFieldBlock): label = _('Date field') icon = 'date' + def get_searchable_content(self, value, data): + return None + class HTML5TimeInput(forms.TimeInput): input_type = 'time' @@ -206,6 +220,9 @@ class TimeFieldBlock(OptionalFormFieldBlock): label = _('Time field') icon = 'time' + def get_searchable_content(self, value, data): + return None + class DateTimePickerInput(forms.SplitDateTimeWidget): def __init__(self, attrs=None, date_format=None, time_format=None): @@ -232,6 +249,9 @@ class DateTimeFieldBlock(OptionalFormFieldBlock): label = _('Date+time field') icon = 'date' + def get_searchable_content(self, value, data): + return None + class ImageFieldBlock(OptionalFormFieldBlock): field_class = forms.ImageField @@ -240,6 +260,9 @@ class ImageFieldBlock(OptionalFormFieldBlock): label = _('Image field') icon = 'image' + def get_searchable_content(self, value, data): + return None + class FileFieldBlock(OptionalFormFieldBlock): field_class = forms.FileField @@ -248,6 +271,9 @@ class FileFieldBlock(OptionalFormFieldBlock): label = _('File field') icon = 'download' + def get_searchable_content(self, value, data): + return None + class FormFieldsBlock(StreamBlock): text_markup = RichTextBlock(group=_('Other'), label=_('Paragraph'))