当前位置: 首页>>代码示例>>Python>>正文


Python Answer.points方法代码示例

本文整理汇总了Python中models.Answer.points方法的典型用法代码示例。如果您正苦于以下问题:Python Answer.points方法的具体用法?Python Answer.points怎么用?Python Answer.points使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Answer的用法示例。


在下文中一共展示了Answer.points方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: question_storage

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import points [as 别名]
def question_storage(url):
    # Split into book and page URLs, aborting if the URL doesn't contain both.
    try:
        book_url, page_url = url.split('/', 1)
    except ValueError:
        abort(404)

    # Process the request.
    try:
        # See if we've saving and checking data or just reading back what data is available.
        if request.args:
            result = {}
            # We have arguments -- save and check data.
            for question_label, new_answer_string in request.args.items():
                # Find this question.
                question = (
                    # Look for the question...
                    db.session.query(Question).
                    # on the current page of this book...
                    select_from(Book).join(Page).filter(Page.url == page_url).
                    # whose label matches current question.
                    join(Question).filter(Question.label == question_label).one()
                )

                # Get feedback for the answer provided.
                points, pointsPossible, feedbackString = find_feedback(question, new_answer_string)

                # Save the answer provided. First, see if an answer already exists.
                answer = (
                    # Look for the answer...
                    db.session.query(Answer).
                    # to the current question...
                    select_from(Question).filter(Question.id == question.id).
                    # which came from the current user.
                    join(Answer).filter(Answer.user_id == current_user.id).scalar()
                )
                # If it doesn't, create one.
                if not answer:
                    answer = Answer(user_id=current_user.id, question_id=question.id)
                    db.session.add(answer)
                # Update the answer and save it.
                answer.string = new_answer_string
                answer.points = points
                db.session.commit()

                # Record grading info to return.
                result[question_label] = [points, pointsPossible, feedbackString]
            return jsonify(result)
        else:
            # No arguments -- load data. First, produce a dict of all answers for this user.
            result = {}
            questions = (
                # Look for all the questions...
                db.session.query(Question).
                # On the current page of the current book.
                select_from(Book).join(Page).filter(Page.url == page_url).join(Question))
            # Walk through each question.
            for question in questions:
                # See if this user has an answer for the current question.
                answer = (
                    # Retrieve the Answer.string...
                    db.session.query(Answer.string).
                    # from the current question...
                    select_from(Question).filter(Question.id == question.id).
                    # from the current user's answer to the current question.
                    join(Answer).filter(Answer.user_id == current_user.id).scalar()
                )
                # If so, provide it to the client.
                if answer:
                    # Look up feedback for this answer.
                    points, pointsPossible, feedbackString = find_feedback(question, answer)
                    result[question.label] = [answer, points, pointsPossible, feedbackString]
            return jsonify(result)
    except NoResultFound:
        abort(404)
开发者ID:bjones1,项目名称:ece3724_inclass,代码行数:77,代码来源:book_webapp.py


注:本文中的models.Answer.points方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。