Skip to content

Fields

hypha.apply.api.v1.review.fields

ScoredAnswerListField

ScoredAnswerListField(*args, **kwargs)

Bases: ListField

Source code in hypha/apply/api/v1/review/fields.py
def __init__(self, *args, **kwargs):
    draft = kwargs.pop("draft", False)
    super().__init__(*args, **kwargs)
    if draft:
        self.childs = [
            serializers.CharField(
                required=False, allow_null=True, allow_blank=True
            ),
            serializers.ChoiceField(choices=RATE_CHOICES),
        ]

childs class-attribute instance-attribute

childs = [CharField(), ChoiceField(choices=RATE_CHOICES)]

run_child_validation

run_child_validation(data)
Source code in hypha/apply/api/v1/review/fields.py
def run_child_validation(self, data):
    result = []
    errors = OrderedDict()

    for idx, item in enumerate(data):
        try:
            result.append(self.childs[idx].run_validation(item))
        except ValidationError as e:
            errors[idx] = e.detail

    if not errors:
        return result
    raise ValidationError(errors)