本文整理汇总了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)