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


Python Question.type方法代码示例

本文整理汇总了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)
开发者ID:zhiaixuexi,项目名称:data_service_aggregation,代码行数:20,代码来源:ctrls.py

示例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
开发者ID:idreyn,项目名称:achieve-backend,代码行数:42,代码来源:parse.py


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