web.py 文件源码

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

项目:census 作者: ioddly 项目源码 文件源码
def update(name, user=None):
    if not user: return users.login_required()
    question = census.questions[name]
    form = question.form(user, request.forms)
    # TODO: WTForm should automatically figure out request.forms, but no combination of arguments has actually worked
    if len(request.forms.getall("answer")) > 1:
        # TODO: malformed input possible here because this is unaware of the question's actual type
        form.answer.data = request.forms.getall("answer")
    elif len(request.forms.getall("answer")) == 0:
        # Check to see if question was answered; if yes, this is an attempt to delete the answer, if not, leave it be
        if question.answered(user):
            form.answer.data = []
        else:
            # If it is not just don't do anything
            return {}
    else:
        form.answer.data = request.forms.get("answer")

    # If only one answer is submitted for checkboxed, this will be returned as a string rather than a list with a
    # single element
    if question.CHART_TYPE == 'check' and type(form.answer.data) == str:
        form.answer.data = [form.answer.data]

    if form.validate():
        res = question.save_answer(user, form.answer.data)
        return {}
    return form.errors
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号