Skip to content

Blocks

hypha.apply.stream_forms.blocks

CHARFIELD_FORMATS module-attribute

CHARFIELD_FORMATS = [('email', gettext_lazy('Email')), ('url', gettext_lazy('URL'))]

FormFieldBlock

Bases: StructBlock

field_label class-attribute instance-attribute

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

help_text class-attribute instance-attribute

help_text = TextBlock(required=False, label=gettext_lazy('Help text'))
help_link = URLBlock(required=False, label=gettext_lazy('Help link'))

field_class class-attribute instance-attribute

field_class = CharField

widget class-attribute instance-attribute

widget = None

Meta

template class-attribute instance-attribute
template = 'stream_forms/render_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)

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 "-"

OptionalFormFieldBlock

Bases: FormFieldBlock

field_label class-attribute instance-attribute

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

help_text class-attribute instance-attribute

help_text = TextBlock(required=False, label=gettext_lazy('Help text'))
help_link = URLBlock(required=False, label=gettext_lazy('Help link'))

field_class class-attribute instance-attribute

field_class = CharField

widget class-attribute instance-attribute

widget = None

required class-attribute instance-attribute

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

Meta

template class-attribute instance-attribute
template = 'stream_forms/render_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)

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 "-"

CharFieldBlock

Bases: OptionalFormFieldBlock

field_label class-attribute instance-attribute

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

help_text class-attribute instance-attribute

help_text = TextBlock(required=False, label=gettext_lazy('Help text'))
help_link = URLBlock(required=False, label=gettext_lazy('Help link'))

field_class class-attribute instance-attribute

field_class = CharField

widget class-attribute instance-attribute

widget = None

required class-attribute instance-attribute

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

format class-attribute instance-attribute

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

default_value class-attribute instance-attribute

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

Meta

label class-attribute instance-attribute
label = gettext_lazy('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_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)

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)

no_response

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

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_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())

MultiInputCharFieldBlock

Bases: CharFieldBlock

field_label class-attribute instance-attribute

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

help_text class-attribute instance-attribute

help_text = TextBlock(required=False, label=gettext_lazy('Help text'))
help_link = URLBlock(required=False, label=gettext_lazy('Help link'))

field_class class-attribute instance-attribute

field_class = CharField

widget class-attribute instance-attribute

widget = None

required class-attribute instance-attribute

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

format class-attribute instance-attribute

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

default_value class-attribute instance-attribute

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

number_of_inputs class-attribute instance-attribute

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

add_button_text class-attribute instance-attribute

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

Meta

label class-attribute instance-attribute
label = gettext_lazy('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)

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 "-"

TextFieldBlock

Bases: OptionalFormFieldBlock

field_label class-attribute instance-attribute

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

help_text class-attribute instance-attribute

help_text = TextBlock(required=False, label=gettext_lazy('Help text'))
help_link = URLBlock(required=False, label=gettext_lazy('Help link'))

field_class class-attribute instance-attribute

field_class = CharField

required class-attribute instance-attribute

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

default_value class-attribute instance-attribute

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

word_limit class-attribute instance-attribute

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

widget class-attribute instance-attribute

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

Meta

label class-attribute instance-attribute
label = gettext_lazy('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)

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)

no_response

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

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())

NumberFieldBlock

Bases: OptionalFormFieldBlock

field_label class-attribute instance-attribute

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

help_text class-attribute instance-attribute

help_text = TextBlock(required=False, label=gettext_lazy('Help text'))
help_link = URLBlock(required=False, label=gettext_lazy('Help link'))

field_class class-attribute instance-attribute

field_class = CharField

required class-attribute instance-attribute

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

default_value class-attribute instance-attribute

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

widget class-attribute instance-attribute

widget = NumberInput

Meta

label class-attribute instance-attribute
label = gettext_lazy('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)

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)

no_response

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

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

CheckboxFieldBlock

Bases: OptionalFormFieldBlock

field_label class-attribute instance-attribute

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

help_text class-attribute instance-attribute

help_text = TextBlock(required=False, label=gettext_lazy('Help text'))
help_link = URLBlock(required=False, label=gettext_lazy('Help link'))

widget class-attribute instance-attribute

widget = None

required class-attribute instance-attribute

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

default_value class-attribute instance-attribute

default_value = BooleanBlock(required=False)

field_class class-attribute instance-attribute

field_class = BooleanField

Meta

label class-attribute instance-attribute
label = gettext_lazy('Checkbox field')
icon class-attribute instance-attribute
icon = 'tick-inverse'

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)

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

RadioButtonsFieldBlock

Bases: OptionalFormFieldBlock

field_label class-attribute instance-attribute

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

help_text class-attribute instance-attribute

help_text = TextBlock(required=False, label=gettext_lazy('Help text'))
help_link = URLBlock(required=False, label=gettext_lazy('Help link'))

required class-attribute instance-attribute

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

choices class-attribute instance-attribute

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

field_class class-attribute instance-attribute

field_class = ChoiceField

widget class-attribute instance-attribute

widget = RadioSelect

Meta

label class-attribute instance-attribute
label = gettext_lazy('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

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)

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 "-"

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

GroupToggleBlock

Bases: FormFieldBlock

field_label class-attribute instance-attribute

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

help_text class-attribute instance-attribute

help_text = TextBlock(required=False, label=gettext_lazy('Help text'))
help_link = URLBlock(required=False, label=gettext_lazy('Help link'))

required class-attribute instance-attribute

required = BooleanBlock(label=gettext_lazy('Required'), default=True, required=False)

choices class-attribute instance-attribute

choices = ListBlock(CharBlock(label=gettext_lazy('Choice')), help_text='Please create only two choices for toggle. First choice will revel the group and the second hide it. Additional choices will be ignored.')

field_class class-attribute instance-attribute

field_class = ChoiceField

widget class-attribute instance-attribute

widget = RadioSelect

Meta

label class-attribute instance-attribute
label = gettext_lazy('Group fields')
icon class-attribute instance-attribute
icon = 'group'
help_text class-attribute instance-attribute
help_text = 'Remember to end group using Group fields end block.'

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

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)

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 "-"

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)
    field_choices = [(choice, choice) for choice in struct_value["choices"]]
    total_choices = len(field_choices)
    if total_choices > 2:
        # For toggle we need only two choices
        field_choices = field_choices[:2]
    elif total_choices < 2:
        field_choices = [
            ("yes", "Yes"),
            ("no", "No"),
        ]
    kwargs["choices"] = field_choices
    return kwargs

GroupToggleEndBlock

Bases: StaticBlock

Meta

label class-attribute instance-attribute
label = 'Group fields end'
icon class-attribute instance-attribute
icon = 'group'
admin_text class-attribute instance-attribute
admin_text = 'End of Group fields Block'

DropdownFieldBlock

Bases: RadioButtonsFieldBlock

field_label class-attribute instance-attribute

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

help_text class-attribute instance-attribute

help_text = TextBlock(required=False, label=gettext_lazy('Help text'))
help_link = URLBlock(required=False, label=gettext_lazy('Help link'))

field_class class-attribute instance-attribute

field_class = ChoiceField

required class-attribute instance-attribute

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

choices class-attribute instance-attribute

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

widget class-attribute instance-attribute

widget = Select

Meta

label class-attribute instance-attribute
label = gettext_lazy('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

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)

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 "-"

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

CheckboxesFieldBlock

Bases: OptionalFormFieldBlock

field_label class-attribute instance-attribute

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

help_text class-attribute instance-attribute

help_text = TextBlock(required=False, label=gettext_lazy('Help text'))
help_link = URLBlock(required=False, label=gettext_lazy('Help link'))

required class-attribute instance-attribute

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

checkboxes class-attribute instance-attribute

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

field_class class-attribute instance-attribute

field_class = MultipleChoiceField

widget class-attribute instance-attribute

widget = CheckboxSelectMultiple

Meta

label class-attribute instance-attribute
label = gettext_lazy('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

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)

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",
    }

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)

no_response

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

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

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]

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

DatePickerInput

DatePickerInput(*args, **kwargs)

Bases: DateInput

Source code in hypha/apply/stream_forms/blocks.py
def __init__(self, *args, **kwargs):
    attrs = kwargs.get("attrs")
    if attrs is None:
        attrs = {}
    attrs.update(
        {
            "data-provide": "datepicker",
            "data-date-format": "yyyy-mm-dd",
        }
    )
    kwargs["attrs"] = attrs
    super().__init__(*args, **kwargs)

DateFieldBlock

Bases: OptionalFormFieldBlock

field_label class-attribute instance-attribute

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

help_text class-attribute instance-attribute

help_text = TextBlock(required=False, label=gettext_lazy('Help text'))
help_link = URLBlock(required=False, label=gettext_lazy('Help link'))

required class-attribute instance-attribute

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

default_value class-attribute instance-attribute

default_value = DateBlock(required=False)

field_class class-attribute instance-attribute

field_class = DateField

widget class-attribute instance-attribute

widget = DatePickerInput

Meta

label class-attribute instance-attribute
label = gettext_lazy('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)

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