fields.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:eq-survey-runner 作者: ONSdigital 项目源码 文件源码
def get_select_field(answer, label, guidance, error_messages):
    validate_with = get_mandatory_validator(answer, error_messages, 'MANDATORY_RADIO')

    # We use a custom coerce function to avoid a defect where Python NoneType
    # is coerced to the string 'None' which clashes with legitimate Radio field
    # values of 'None'; i.e. there is no way to differentiate between the user
    # not providing an answer and them selecting the 'None' option otherwise.
    # https://github.com/ONSdigital/eq-survey-runner/issues/1013
    # See related WTForms PR: https://github.com/wtforms/wtforms/pull/288

    return SelectField(
        label=label,
        description=guidance,
        choices=build_choices(answer['options']),
        validators=validate_with,
        coerce=_coerce_str_unless_none,
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号