本文整理汇总了Python中models.Question.difficulty方法的典型用法代码示例。如果您正苦于以下问题:Python Question.difficulty方法的具体用法?Python Question.difficulty怎么用?Python Question.difficulty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Question
的用法示例。
在下文中一共展示了Question.difficulty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_test_backup
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import difficulty [as 别名]
def create_test_backup(request):
test_obj = json.loads(request.body)
test = Test()
#import pdb; pdb.set_trace()
if request.user.is_authenticated():
owner = User_Profile.objects.filter(user = request.user)
test.owner = owner[0]
test.test_name = test_obj['PRE_TEST']['test_name']
#test.subject = test_obj['PRE_TEST'].subject
#test.target_exam = test_obj['PRE_TEST'].target_exam
#test.topics = test_obj['PRE_TEST'].topics_included
test.total_time = test_obj['PRE_TEST']['total_time']
test.pass_criteria = test_obj['PRE_TEST']['pass_criteria']
test.assoicated_class = Class.objects.get(pk=test_obj['CLASS_INFO'])
test.save()
try:
for item in test_obj['QUESTIONS']:
question = Question()
question.question_text = item['question_text']
question.explanation = item['explanation']
question.options = json.dumps(item['options'])
question.hint = item['hint']
question.difficulty = item['difficulty_level']
question.points = item['points']
question.owner = owner[0]
#question.target_exam = test.target_exam
#question.subject = test.subject
#question.topic = item.topic
question.save()
test.questions.add(question)
data = {"status" : "success"}
return JsonResponse(data)
except Exception, e:
raise e
示例2: post
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import difficulty [as 别名]
def post(self, request, subject, format=None):
# todo
data = request.data
model = Question()
serializer = QuestionPostSerializer(data=data,many=True)
if not serializer.is_valid():
err = {}
err['msg'] = serializer.errors
return Response(err)
li=[]
for i in data:
obj1 = Content.objects.get(entry=subject)
if obj1:
obj = Question()
obj.que = i['que']
obj.subject = subject
obj.difficulty = i['difficulty']
obj.ref = obj1
obj.save()
li.append(obj)
con = QuestionSerializer(li,many=True)
return Response(con.data)
示例3: post
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import difficulty [as 别名]
def post(self):
# Grab album from url
urlstring = self.request.POST['album']
album_key = ndb.Key(urlsafe=urlstring)
album = album_key.get()
# Check whether we're storing a album or a Question
if self.request.GET['album'] == '1':
album.title = self.request.POST['albumTitle']
album.category = self.request.POST['categoryTitle']
album.put()
time.sleep(0.1)
# Save album and redirect to edit if the user clicks on 'Save and continue editing'
# Else, save album and go back to the main page which lists all albums
if self.request.POST.get('stay') == '1':
self.redirect('/edit?album=1&id='+urlstring)
else:
if album.album_type == 'match':
self.redirect('/match')
elif album.album_type == 'correlate':
self.redirect('/correlate')
else:
self.redirect('/oddmanout')
else:
# Create Question with the album as parent for strong consistency
question = ""
new = "1"
if self.request.POST['question'] == "":
question = Question(parent=album_key)
question.question_id = question.put().id()
else:
new = "0"
question_url = self.request.POST['question']
question_key = ndb.Key(urlsafe=question_url)
question = question_key.get()
question.title = self.request.get('title')
question.fact = self.request.get('fact')
question.effect = self.request.get('revealEffect')
question.difficulty = self.request.get('difficulty')
# Create answer choices
answer = int(self.request.get('correct_answer'))
input_images = self.request.get('image', allow_multiple=True)
num_images = 4
if album.album_type == 'correlate':
num_images = 5
image_list = []
for i in range(num_images):
img = ""
input_img = input_images[i]
# If old retrieve the Image
if new == "0":
img = question.images[i]
else:
img = Image()
# Resize image
if input_img:
op_img = images.Image(input_img)
op_img.resize(width=256, height=256, crop_to_fit=True)
result_img = op_img.execute_transforms(output_encoding=images.JPEG)
img.image = result_img
# Set the title and correct fields
if answer == i:
img.title = "correct_answer_"+str(i)
img.correct = True
elif num_images == 5 and i == 0: # This is if the album is of type Correlate
img.title = "main_image_"+str(i)
img.correct = False
else:
img.title = "incorrect_answer_"+str(i)
img.correct = False
# If old Question, free up the old Image and put in new Image
if new == "0":
question.images.pop(i)
question.images.insert(i, img)
else:
question.images.append(img)
question.put()
# Query all Question(s) for the album in recently added order for /create
# Retrieve previously input values, and indicate whether this is a new album (edit)
questions = Question.query(ancestor=album_key).order(-Question.date).fetch()
retrieve = 1
edit = self.request.GET['edit']
template_values = {
'album': album,
'album_type': album.album_type,
'questions': questions,
'edit': edit,
'retrieve': retrieve
}
template = JINJA_ENVIRONMENT.get_template('create.html')
self.response.write(template.render(template_values))