Skip to content
Snippets Groups Projects
Commit ef3480bf authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Allow blocks to control how they output the values and no response

parent 26c0fb45
No related branches found
No related tags found
No related merge requests found
......@@ -80,6 +80,9 @@ class DurationBlock(ApplicationMustIncludeFieldBlock):
field_kwargs['choices'] = self.DURATION_OPTIONS.items()
return field_kwargs
def format_data(self, data):
return self.DURATION_OPTIONS[int(data)]
class Meta:
icon = 'date'
......
......@@ -50,9 +50,20 @@ class FormFieldBlock(StructBlock):
return self.get_field_class(struct_value)(
**self.get_field_kwargs(struct_value))
def get_context(self, value, parent_context):
context = super().get_context(value, parent_context)
parent_context['data'] = self.format_data(parent_context['data']) or self.no_response()
return context
def get_searchable_content(self, value, data):
return str(data)
def format_data(self, data):
return data
def no_responose(self):
return "No response"
class OptionalFormFieldBlock(FormFieldBlock):
required = BooleanBlock(label=_('Required'), required=False)
......@@ -126,6 +137,9 @@ class CheckboxFieldBlock(FormFieldBlock):
def get_searchable_content(self, value, data):
return None
def no_responose(self):
return False
class RadioButtonsFieldBlock(OptionalFormFieldBlock):
choices = ListBlock(CharBlock(label=_('Choice')))
......
<div>
<h5>{{ value.field_label }}</h5>
<div>{% block data_display %}{{ data|default:"No response" }}{% endblock %}</div>
<div>{% block data_display %}{{ data }}{% endblock %}</div>
</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment