本文整理汇总了Python中models.Question.effect方法的典型用法代码示例。如果您正苦于以下问题:Python Question.effect方法的具体用法?Python Question.effect怎么用?Python Question.effect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Question
的用法示例。
在下文中一共展示了Question.effect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import effect [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))