Skip to content

Pii blocks

hypha.apply.funds.pii_blocks

Application form field blocks that can be marked as personal information.

Only the answers of an application form are ever redacted, see AccessFormData.render_answer(), so the "Personal information" checkbox is offered on these blocks alone. Review, determination and project forms keep using the plain field blocks.

The blocks are thin subclasses that add nothing but the checkbox, so they deconstruct into migrations exactly like the blocks they extend and answer to the same isinstance() checks.

PIICharFieldBlock

Bases: PIIFieldMixin, CharFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.CharField

widget class-attribute instance-attribute

widget = None

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

format class-attribute instance-attribute

format = ChoiceBlock(choices=CHARFIELD_FORMATS, required=False, label=_('Format'))

default_value class-attribute instance-attribute

default_value = CharBlock(required=False, label=_('Default value'))

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Text field (single line)')
icon class-attribute instance-attribute
icon = 'minus'
template class-attribute instance-attribute
template = 'stream_forms/render_unsafe_field.html'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    text_format = struct_value["format"]
    if text_format == "url":
        return forms.URLField
    if text_format == "email":
        return forms.EmailField
    return super().get_field_class(struct_value)

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = {
        "label": struct_value["field_label"],
        "help_text": conditional_escape(struct_value["help_text"]),
        "required": struct_value.get("required", False),
    }
    if "default_value" in struct_value:
        kwargs["initial"] = struct_value["default_value"]
    form_widget = self.get_widget(struct_value)
    if form_widget is not None:
        kwargs["widget"] = form_widget
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    return nh3_value(str(data))

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    # CharField acts as a fallback. Force data to string
    data = str(data)
    return nh3.clean(data or "", tags=set())

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return "-"

PIIMultiInputCharFieldBlock

Bases: PIIFieldMixin, MultiInputCharFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.CharField

widget class-attribute instance-attribute

widget = None

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

format class-attribute instance-attribute

format = ChoiceBlock(choices=CHARFIELD_FORMATS, required=False, label=_('Format'))

default_value class-attribute instance-attribute

default_value = CharBlock(required=False, label=_('Default value'))

number_of_inputs class-attribute instance-attribute

number_of_inputs = IntegerBlock(default=2, label=_('Max number of inputs'))

add_button_text class-attribute instance-attribute

add_button_text = CharBlock(required=False, default=_('Add new item'))

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Text field (single line) (multiple inputs)')
icon class-attribute instance-attribute
icon = 'bars'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    text_format = struct_value["format"]
    if text_format == "url":
        return forms.URLField
    if text_format == "email":
        return forms.EmailField
    return super().get_field_class(struct_value)

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = {
        "label": struct_value["field_label"],
        "help_text": conditional_escape(struct_value["help_text"]),
        "required": struct_value.get("required", False),
    }
    if "default_value" in struct_value:
        kwargs["initial"] = struct_value["default_value"]
    form_widget = self.get_widget(struct_value)
    if form_widget is not None:
        kwargs["widget"] = form_widget
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    return nh3_value(str(data))

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    # CharField acts as a fallback. Force data to string
    data = str(data)
    return nh3.clean(data or "", tags=set())

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return "-"

PIITextFieldBlock

Bases: PIIFieldMixin, TextFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.CharField

widget class-attribute instance-attribute

widget = forms.Textarea(attrs={'rows': 5})

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

default_value class-attribute instance-attribute

default_value = TextBlock(required=False, label=_('Default value'))

word_limit class-attribute instance-attribute

word_limit = IntegerBlock(default=1000, label=_('Word limit'))

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Text field (multi line)')
icon class-attribute instance-attribute
icon = 'edit'
template class-attribute instance-attribute
template = 'stream_forms/render_unsafe_field.html'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = {
        "label": struct_value["field_label"],
        "help_text": conditional_escape(struct_value["help_text"]),
        "required": struct_value.get("required", False),
    }
    if "default_value" in struct_value:
        kwargs["initial"] = struct_value["default_value"]
    form_widget = self.get_widget(struct_value)
    if form_widget is not None:
        kwargs["widget"] = form_widget
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    return nh3_value(str(data))

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    return nh3.clean(data or "", tags=set())

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return "-"

PIIRichTextFieldBlock

Bases: PIIFieldMixin, RichTextFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.CharField

widget class-attribute instance-attribute

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

default_value class-attribute instance-attribute

default_value = TextBlock(required=False, label=_('Default value'))

word_limit class-attribute instance-attribute

word_limit = IntegerBlock(default=1000, label=_('Word limit'))

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Rich text field')
icon class-attribute instance-attribute
icon = 'form'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = {
        "label": struct_value["field_label"],
        "help_text": conditional_escape(struct_value["help_text"]),
        "required": struct_value.get("required", False),
    }
    if "default_value" in struct_value:
        kwargs["initial"] = struct_value["default_value"]
    form_widget = self.get_widget(struct_value)
    if form_widget is not None:
        kwargs["widget"] = form_widget
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    return nh3_value(str(data))

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/utils/blocks.py
def get_searchable_content(self, value, data):
    return nh3.clean(data or "", tags=set())

no_response

no_response()
Source code in hypha/apply/utils/blocks.py
def no_response(self):
    return "<p>-</p>"

PIIMarkdownTextFieldBlock

Bases: PIIFieldMixin, MarkdownTextFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.CharField

widget class-attribute instance-attribute

widget = PagedownWidget()

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

default_value class-attribute instance-attribute

default_value = TextBlock(required=False, label=_('Default value'))

word_limit class-attribute instance-attribute

word_limit = IntegerBlock(default=1000, label=_('Word limit'))

template class-attribute instance-attribute

template = ''

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Markdown text field')
icon class-attribute instance-attribute
icon = 'form'
template class-attribute instance-attribute
template = 'stream_forms/render_markdown_field.html'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = {
        "label": struct_value["field_label"],
        "help_text": conditional_escape(struct_value["help_text"]),
        "required": struct_value.get("required", False),
    }
    if "default_value" in struct_value:
        kwargs["initial"] = struct_value["default_value"]
    form_widget = self.get_widget(struct_value)
    if form_widget is not None:
        kwargs["widget"] = form_widget
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    return nh3_value(str(data))

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/utils/blocks.py
def get_searchable_content(self, value, data):
    return nh3.clean(data or "", tags=set())

no_response

no_response()
Source code in hypha/apply/utils/blocks.py
def no_response(self):
    return "<p>-</p>"

PIINumberFieldBlock

Bases: PIIFieldMixin, NumberFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.CharField

widget class-attribute instance-attribute

widget = forms.NumberInput

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

default_value class-attribute instance-attribute

default_value = CharBlock(required=False, label=_('Default value'))

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Number field')
icon class-attribute instance-attribute
icon = 'decimal'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = {
        "label": struct_value["field_label"],
        "help_text": conditional_escape(struct_value["help_text"]),
        "required": struct_value.get("required", False),
    }
    if "default_value" in struct_value:
        kwargs["initial"] = struct_value["default_value"]
    form_widget = self.get_widget(struct_value)
    if form_widget is not None:
        kwargs["widget"] = form_widget
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    return nh3_value(str(data))

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    return None

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return "-"

PIICheckboxFieldBlock

Bases: PIIFieldMixin, CheckboxFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.BooleanField

widget class-attribute instance-attribute

widget = None

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

default_value class-attribute instance-attribute

default_value = BooleanBlock(required=False)

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Checkbox field')
icon class-attribute instance-attribute
icon = 'tick-inverse'
template class-attribute instance-attribute
template = 'stream_forms/render_checkbox_field.html'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = {
        "label": struct_value["field_label"],
        "help_text": conditional_escape(struct_value["help_text"]),
        "required": struct_value.get("required", False),
    }
    if "default_value" in struct_value:
        kwargs["initial"] = struct_value["default_value"]
    form_widget = self.get_widget(struct_value)
    if form_widget is not None:
        kwargs["widget"] = form_widget
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    return nh3_value(str(data))

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    return None

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return False

PIIRadioButtonsFieldBlock

Bases: PIIFieldMixin, RadioButtonsFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.ChoiceField

widget class-attribute instance-attribute

widget = forms.RadioSelect

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

choices class-attribute instance-attribute

choices = ListBlock(CharBlock(label=_('Choice')))

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Radio buttons')
icon class-attribute instance-attribute
icon = 'radio-empty'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = super().get_field_kwargs(struct_value)
    kwargs["choices"] = [(choice, choice) for choice in struct_value["choices"]]
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    return nh3_value(str(data))

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    return str(data)

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return "-"

PIIDropdownFieldBlock

Bases: PIIFieldMixin, DropdownFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.ChoiceField

widget class-attribute instance-attribute

widget = forms.Select

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

choices class-attribute instance-attribute

choices = ListBlock(CharBlock(label=_('Choice')))

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Dropdown field')
icon class-attribute instance-attribute
icon = 'arrow-down'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = super().get_field_kwargs(struct_value)
    kwargs["choices"].insert(0, BLANK_CHOICE_DASH[0])
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    return nh3_value(str(data))

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    return str(data)

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return "-"

PIICheckboxesFieldBlock

Bases: PIIFieldMixin, CheckboxesFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.MultipleChoiceField

widget class-attribute instance-attribute

widget = forms.CheckboxSelectMultiple

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

checkboxes class-attribute instance-attribute

checkboxes = ListBlock(CharBlock(label=_('Checkbox')))

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Multiple checkboxes field')
icon class-attribute instance-attribute
icon = 'tasks'
template class-attribute instance-attribute
template = 'stream_forms/render_list_field.html'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = super().get_field_kwargs(struct_value)
    kwargs["choices"] = [(choice, choice) for choice in struct_value["checkboxes"]]
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    if not data:
        return data
    base_prepare = super().prepare_data
    return [base_prepare(value, item, serialize) for item in data]

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    return data

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return "-"

PIIDateFieldBlock

Bases: PIIFieldMixin, DateFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.DateField

widget class-attribute instance-attribute

widget = DatePickerInput

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

default_value class-attribute instance-attribute

default_value = DateBlock(required=False)

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Date field')
icon class-attribute instance-attribute
icon = 'date'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = {
        "label": struct_value["field_label"],
        "help_text": conditional_escape(struct_value["help_text"]),
        "required": struct_value.get("required", False),
    }
    if "default_value" in struct_value:
        kwargs["initial"] = struct_value["default_value"]
    form_widget = self.get_widget(struct_value)
    if form_widget is not None:
        kwargs["widget"] = form_widget
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)
Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    if value:
        return parse(value).date()

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    return nh3_value(str(data))

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    return None

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return "-"

PIITimeFieldBlock

Bases: PIIFieldMixin, TimeFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.TimeField

widget class-attribute instance-attribute

widget = HTML5TimeInput

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

default_value class-attribute instance-attribute

default_value = TimeBlock(required=False)

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Time field')
icon class-attribute instance-attribute
icon = 'time'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = {
        "label": struct_value["field_label"],
        "help_text": conditional_escape(struct_value["help_text"]),
        "required": struct_value.get("required", False),
    }
    if "default_value" in struct_value:
        kwargs["initial"] = struct_value["default_value"]
    form_widget = self.get_widget(struct_value)
    if form_widget is not None:
        kwargs["widget"] = form_widget
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)
Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    if value:
        return parse(value).time()

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    return nh3_value(str(data))

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    return None

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return "-"

PIIDateTimeFieldBlock

Bases: PIIFieldMixin, DateTimeFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.SplitDateTimeField

widget class-attribute instance-attribute

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

default_value class-attribute instance-attribute

default_value = DateTimeBlock(required=False)

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Date+time field')
icon class-attribute instance-attribute
icon = 'date'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = {
        "label": struct_value["field_label"],
        "help_text": conditional_escape(struct_value["help_text"]),
        "required": struct_value.get("required", False),
    }
    if "default_value" in struct_value:
        kwargs["initial"] = struct_value["default_value"]
    form_widget = self.get_widget(struct_value)
    if form_widget is not None:
        kwargs["widget"] = form_widget
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)
Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    if value:
        return isoparse(value)

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize=False)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize=False):
    return nh3_value(str(data))

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    return None

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return "-"

PIIImageFieldBlock

Bases: PIIFieldMixin, ImageFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = forms.ImageField

widget class-attribute instance-attribute

widget = ClearableFileInput

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Image field')
icon class-attribute instance-attribute
icon = 'image'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = {
        "label": struct_value["field_label"],
        "help_text": conditional_escape(struct_value["help_text"]),
        "required": struct_value.get("required", False),
    }
    if "default_value" in struct_value:
        kwargs["initial"] = struct_value["default_value"]
    form_widget = self.get_widget(struct_value)
    if form_widget is not None:
        kwargs["widget"] = form_widget
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize):
    if serialize:
        if data:
            return data.serialize()
        return None

    return data

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    return None

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return "-"

PIIFileFieldBlock

Bases: PIIFieldMixin, FileFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = SingleFileField

widget class-attribute instance-attribute

widget = None

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

label class-attribute instance-attribute
label = _('Single File field')
icon class-attribute instance-attribute
icon = 'download'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = super().get_field_kwargs(struct_value)
    kwargs["help_text"] = mark_safe(
        _("{help_text} Accepted file types are {file_types}").format(
            help_text=kwargs["help_text"],
            file_types=settings.FILE_ACCEPT_ATTR_VALUE,
        )
    )
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize):
    if serialize:
        if data:
            return data.serialize()
        return None

    return data

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    return None

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return "-"

PIIMultiFileFieldBlock

Bases: PIIFieldMixin, MultiFileFieldBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(required=False, label=_('Help text'))

field_class class-attribute instance-attribute

field_class = MultiFileField

widget class-attribute instance-attribute

widget = None

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

icon class-attribute instance-attribute
icon = 'download'
label class-attribute instance-attribute
label = _('Multiple File field')
template class-attribute instance-attribute
template = 'stream_forms/render_multi_file_field.html'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_class(self, struct_value):
    return self.field_class

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = super().get_field_kwargs(struct_value)
    kwargs["help_text"] = mark_safe(
        _("{help_text} Accepted file types are {file_types}").format(
            help_text=kwargs["help_text"],
            file_types=settings.FILE_ACCEPT_ATTR_VALUE,
        )
    )
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)

The value to display the question with.

Blocks that derive parts of the question, such as a label taken from a linked object, apply those defaults here so that every way of rendering the field gets them.

Source code in hypha/apply/stream_forms/blocks.py
def get_display_value(self, value):
    """The value to display the question with.

    Blocks that derive parts of the question, such as a label taken from a
    linked object, apply those defaults here so that every way of rendering
    the field gets them.
    """
    return value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize)
Source code in hypha/apply/stream_forms/blocks.py
def prepare_data(self, value, data, serialize):
    if serialize:
        if data:
            return [file.serialize() for file in data]
        return None
    return data

render

render(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def render(self, value, context):
    data = context.get("data")
    data = self.prepare_data(value, data, context.get("serialize", False))

    context.update(data=data or self.no_response())

    if context.get("serialize"):
        if not data:
            return self.serialize_no_response(value, context)
        return self.serialize(value, context)

    return super().render(value, context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/stream_forms/blocks.py
def get_searchable_content(self, value, data):
    return None

no_response

no_response()
Source code in hypha/apply/stream_forms/blocks.py
def no_response(self):
    return [super().no_response()]

PIICategoryQuestionBlock

Bases: PIIFieldMixin, CategoryQuestionBlock

field_label class-attribute instance-attribute

field_label = CharBlock(label=_('Label'), required=False, help_text=_('Leave blank to use the default Category label'))

help_text class-attribute instance-attribute

help_text = RichTextBlock(label=_('Help text'), required=False, help_text=_('Leave blank to use the default Category help text'))

field_class class-attribute instance-attribute

field_class = forms.CharField

widget class-attribute instance-attribute

widget = None

required class-attribute instance-attribute

required = BooleanBlock(label=_('Required'), required=False)

category class-attribute instance-attribute

category = ModelChooserBlock(required=True, choices=get_categories_as_choices)

multi class-attribute instance-attribute

multi = BooleanBlock(label=_('Multi select'), required=False)

is_pii class-attribute instance-attribute

is_pii = BooleanBlock(label=_('Personal information'), required=False, default=False, help_text=_('Tick this if the answer will contain personally identifiable information, such as a name, address, phone number or date of birth. Only the applicant, their co-applicants and staff will be able to see the answer. Reviewers and other users will see that the question was asked, but not the answer.'))

Meta

template class-attribute instance-attribute
template = 'stream_forms/render_list_field.html'
icon class-attribute instance-attribute
icon = 'folder-open-1'

get_slug

get_slug(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_slug(self, struct_value):
    return force_str(slugify(anyascii(struct_value["field_label"])))

get_field_class

get_field_class(struct_value)
Source code in hypha/apply/categories/blocks.py
def get_field_class(self, struct_value):
    return forms.MultipleChoiceField if struct_value["multi"] else forms.ChoiceField

get_widget

get_widget(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_widget(self, struct_value):
    return self.widget

get_field_kwargs

get_field_kwargs(struct_value)
Source code in hypha/apply/categories/blocks.py
def get_field_kwargs(self, struct_value):
    kwargs = super().get_field_kwargs(struct_value)
    category = self.get_instance(id=struct_value["category"])
    kwargs = self.use_defaults_from_category(kwargs, category)
    choices = list(category.options.values_list("id", "value"))
    widget = self.widget_for_choices(struct_value, choices)
    if widget is ChoicesSelectWidget:
        # A <select> auto-selects its first option, so offer an empty one.
        choices.insert(0, BLANK_CHOICE_DASH[0])
    kwargs.update({"choices": choices, "widget": widget})
    return kwargs

get_field

get_field(struct_value)
Source code in hypha/apply/stream_forms/blocks.py
def get_field(self, struct_value):
    field_kwargs = self.get_field_kwargs(struct_value)
    return self.get_field_class(struct_value)(**field_kwargs)

get_display_value

get_display_value(value)
Source code in hypha/apply/categories/blocks.py
def get_display_value(self, value):
    # Fall back on the category's own name and help text for empty values.
    category_fields = {"field_label": "name", "help_text": "help_text"}

    missing = [field for field in category_fields if not value.get(field)]
    if not missing:
        return value

    # Look the category up once, however many fields fall back on it.
    category = value["category"]
    if isinstance(category, int) or isinstance(category, str):
        category = self.get_instance(id=category)

    defaults = {
        field: getattr(category, category_fields[field]) for field in missing
    }

    # Return a copy, so that the fallbacks are never written back to the
    # stored form definition.
    block = getattr(value, "block", None)
    if block is None:
        display_value = dict(value)
    else:
        display_value = value.__class__(block, value.items())
    display_value.update(defaults)
    return display_value

decode

decode(value)

Convert JSON representation into actual python objects

Source code in hypha/apply/stream_forms/blocks.py
def decode(self, value):
    """Convert JSON representation into actual python objects"""
    return value

serialize

serialize(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize(self, value, context):
    field_kwargs = self.get_field_kwargs(value)
    return {
        "question": field_kwargs["label"],
        "answer": context.get("data"),
        "type": self.name,
    }

serialize_no_response

serialize_no_response(value, context)
Source code in hypha/apply/stream_forms/blocks.py
def serialize_no_response(self, value, context):
    return {
        "question": value["field_label"],
        "answer": "-",
        "type": "no_response",
    }

prepare_data

prepare_data(value, data, serialize)
Source code in hypha/apply/categories/blocks.py
def prepare_data(self, value, data, serialize):
    if not data:
        return data
    if isinstance(data, str):
        data = [data]
    category = self.get_instance(id=value["category"])
    data = category.options.filter(id__in=data).values_list("value", flat=True)
    return data

render

render(value, context)
Source code in hypha/apply/categories/blocks.py
def render(self, value, context):
    return super().render(self.get_display_value(value), context)

get_searchable_content

get_searchable_content(value, data)
Source code in hypha/apply/categories/blocks.py
def get_searchable_content(self, value, data):
    return None

no_response

no_response()
Source code in hypha/apply/categories/blocks.py
def no_response(self):
    return "-"

model_class

model_class()
Source code in hypha/apply/categories/blocks.py
@cached_property
def model_class(self):
    return resolve_model_string("categories.Category")

get_instance

get_instance(id)
Source code in hypha/apply/categories/blocks.py
def get_instance(self, id):
    return self.model_class.objects.get(id=id)

use_defaults_from_category

use_defaults_from_category(kwargs, category)
Source code in hypha/apply/categories/blocks.py
def use_defaults_from_category(self, kwargs, category):
    category_fields = {"label": "name", "help_text": "help_text"}

    for field in category_fields.keys():
        if not kwargs.get(field):
            kwargs[field] = getattr(category, category_fields[field])

    return kwargs

widget_for_choices

widget_for_choices(struct_value, choices)
Source code in hypha/apply/categories/blocks.py
def widget_for_choices(self, struct_value, choices):
    # Pick widget according to number of options to maintain good usability.
    many_options = len(choices) >= SEARCHABLE_SELECT_THRESHOLD
    if struct_value["multi"]:
        return (
            ChoicesSelectMultipleWidget
            if many_options
            else forms.CheckboxSelectMultiple
        )
    return ChoicesSelectWidget if many_options else forms.RadioSelect

unmarked_block_class

unmarked_block_class(block)

The block class a PII-markable block adds the checkbox to.

Lets code that switches on the exact block class keep working for the application form, where the blocks are the subclasses above.

Source code in hypha/apply/funds/pii_blocks.py
def unmarked_block_class(block):
    """The block class a PII-markable block adds the checkbox to.

    Lets code that switches on the exact block class keep working for the
    application form, where the blocks are the subclasses above.
    """
    # `object` ends every MRO and is never a `PIIFieldMixin`, so this always
    # returns: the block's own class for a plain block, the block it extends
    # for one of the subclasses above.
    for block_class in type(block).__mro__:
        if not issubclass(block_class, PIIFieldMixin):
            return block_class