本文整理汇总了Python中question.Question.update_question_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Question.update_question_by_id方法的具体用法?Python Question.update_question_by_id怎么用?Python Question.update_question_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类question.Question
的用法示例。
在下文中一共展示了Question.update_question_by_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: jupd
# 需要导入模块: from question import Question [as 别名]
# 或者: from question.Question import update_question_by_id [as 别名]
def jupd(question_id):
current_app.logger.debug("question.jupd. - " + str(question_id))
question = Question.get_active_question_by_id(question_id)
if question:
if current_user.id == question.user_id:
current_app.logger.warning(request.json)
schema = {
"type" : "object",
"properties" : {
"id" : {"type" : "integer", "maxLength" : 8, "optional" : False},
"quizid" : {"type" : "integer", "maxLength" : 8, "optional" : False},
"qtext" : {"type" : "string", "maxLength" : 4096, "optional" : False},
"answers" : {"type": "array", "items": { "type" : "object", "properties": {"id" : {"type" : "integer", "maxLength" : 8, "optional" : False},
"correct" : {"type" : "string", "enum" : ["T", "F"], "optional" : False}
}}, "maxItems" : 25, "optional" : True},
"lat" : {"type" : "number", "maxLength" : 12, "optional" : False},
"lon" : {"type" : "number", "maxLength" : 12, "optional" : False},
}
}
v = Draft4Validator(schema)
errors = sorted(v.iter_errors(request.json), key = lambda e: e.path)
qid = request.json['id']
qtext = request.json['qtext']
answers = request.json['answers']
latitude = request.json['lat']
longitude = request.json['lon']
if len(errors) == 0:
#TODO - allow displaying unallowed tags as non html tags
#scrubb = scrubber.Scrubber()
#qtext = jinja2.Markup(scrubb.scrub(qtext))
current_app.logger.debug("got a question from DB, id = " + str(question_id))
current_app.logger.debug("id = " + str(qid))
current_app.logger.debug("qtext = '" + qtext + "'")
current_app.logger.debug("answers = " + str(answers))
current_app.logger.debug("latitude = " + str(latitude))
current_app.logger.debug("longitude = " + str(longitude))
results = QuestionResult.get_question_results_by_revision_id(question.revision_id)
if len(results) > 0:
Question.update_question_by_id_and_create_revision(question_id, qtext, latitude, longitude)
else:
Question.update_question_by_id(question_id, qtext, latitude, longitude)
db.session.commit()
current_app.logger.debug("Status - OK")
result = {'staus':'OK'}
return jsonify(result)
else:
if len(qtext) > 4096:
msg = u"Question text is too long. It must be less than 4096 symbols"
current_app.logger.warning(msg)
return jsonify({"status" : "ERROR", "message" : msg})
elif len(answers) > 25:
msg = u"Number of answers must not be greater than 25"
current_app.logger.warning(msg)
return jsonify({"status" : "ERROR", "message" : msg})
else:
msg = u"Error : "
for e in errors:
msg = msg + str(list(e.path)[len(list(e.path))-1]) + " - " + e.message.decode("UTF-8")
current_app.logger.warning(msg)
return jsonify({"status" : "ERROR", "message" : msg})
else:
msg = auth_failure_message + u"update this question"
current_app.logger.warning(msg)
return jsonify({"status" : "ERROR", "message" : msg})
else:
msg = u"No such question found!"
current_app.logger.warning(msg)
return jsonify({"status" : "ERROR", "message" : msg})