Skip to content

Fields

hypha.apply.review.fields

ScoredAnswerWidget

ScoredAnswerWidget(attrs=None)

Bases: MultiWidget

Source code in hypha/apply/review/fields.py
def __init__(self, attrs=None):
    _widgets = (
        TinyMCE(attrs=attrs, mce_attrs=MCE_ATTRIBUTES_SHORT),
        widgets.Select(attrs={"data-score-field": "true"}, choices=RATE_CHOICES),
    )
    super().__init__(_widgets, attrs)

decompress

decompress(value)
Source code in hypha/apply/review/fields.py
def decompress(self, value):
    # We should only hit this on initialisation where we set the default to a list of None
    if value:
        return value
    return [None, None]

render

render(name, value, attrs=None, renderer=None)
Source code in hypha/apply/review/fields.py
def render(self, name, value, attrs=None, renderer=None):
    context = self.get_context(name, value, attrs)
    rendered = []
    # We need to explicitly call the render method on the tinymce widget
    # MultiValueWidget just passes all the context into the template
    for kwargs, widget in zip(
        context["widget"]["subwidgets"], self.widgets, strict=False
    ):
        name = kwargs["name"]
        value = kwargs["value"]
        attrs = kwargs["attrs"]
        rendered.append(widget.render(name, value, attrs, renderer))
    return mark_safe("".join(list(rendered)))

ScoredAnswerField

ScoredAnswerField(*args, **kwargs)

Bases: MultiValueField

Source code in hypha/apply/review/fields.py
def __init__(self, *args, **kwargs):
    fields = (
        forms.CharField(),
        forms.ChoiceField(choices=RATE_CHOICES),
    )

    super().__init__(*args, **kwargs, fields=fields)

widget class-attribute instance-attribute

compress

compress(data_list)
Source code in hypha/apply/review/fields.py
def compress(self, data_list):
    if data_list:
        return [data_list[0], int(data_list[1])]
    else:
        return ["", NA]