本文整理汇总了Python中models.Question.type方法的典型用法代码示例。如果您正苦于以下问题:Python Question.type方法的具体用法?Python Question.type怎么用?Python Question.type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Question
的用法示例。
在下文中一共展示了Question.type方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveQuestionByForm
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import type [as 别名]
def saveQuestionByForm(request, form):
question = Question(title=form.cleaned_data['qs_title'],
description=form.cleaned_data['content'],)
questionType = Question_Type.objects.get(id=form.cleaned_data['qs_type']);#@UndefinedVariable
question.type = questionType
question.user = request.user
question.save()
tag_list = form.cleaned_data['qs_tags'].split(',');
for tag_ele in tag_list:
questionTag = Question_Tag.objects.filter(tag_name=tag_ele) #@UndefinedVariable
if(questionTag.count() > 0):
questionTag = questionTag[0]
else:
questionTag = Question_Tag(tag_name=tag_ele)
questionTag.save()
question.tags.add(questionTag)
示例2: parse_quiz_yaml
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import type [as 别名]
def parse_quiz_yaml(path, string):
d = yaml.load(string)
sugar = make_sugar(path, d)
assert d.get('title') and len(d['title']) > 0, "Quiz is missing title"
assert d.get('subtitle') and len(d['subtitle']) > 0, "Quiz is missing subtitle"
assert d.get('text') and len(d['text']) > 0, "Quiz is missing text body"
assert d.get('questions') and len(d['questions']) > 0, "Quiz has no questions"
assert d.get('email') and len(d['email']) > 0, "Quiz has no email message"
email = d['email']
for k in ['$name','$url']:
assert k in email, "Quiz email is missing parameter %s" % k
questions = d['questions']
for i, q in enumerate(questions):
assert q.get('text'), "Question #%d has no text" % (i + 1)
assert q.get('choices') and len(q['choices']) > 1, "Question #%d needs more than one choice" % (i + 1)
assert q.get('correct'), "Question #%d is missing a correct answer" % (i + 1)
assert q.get('correct') in q['choices'], "Question #%d has a correct answer that is not one of the choices" % (i + 1)
if q.get('type'):
assert q['type'] in [t[0] for t in QUESTION_TYPES]
quiz = Quiz(
title=d['title'],
subtitle=d['subtitle'],
text=sugar(d['text']),
)
quiz.save()
for i, q in enumerate(d['questions']):
for choice in q['choices']:
q['choices'][choice] = sugar(q['choices'][choice])
question = Question(
text=sugar(q['text']),
choices=json.dumps(q['choices']),
correct=q['correct'],
explanation=sugar(q.get('explanation') or ''),
index=i+1
)
if q.get('type'):
question.type = q['type']
question.save()
quiz.questions.add(question)
return md.markdown(email), quiz