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


Python Image.correct方法代码示例

本文整理汇总了Python中models.Image.correct方法的典型用法代码示例。如果您正苦于以下问题:Python Image.correct方法的具体用法?Python Image.correct怎么用?Python Image.correct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Image的用法示例。


在下文中一共展示了Image.correct方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import correct [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))
开发者ID:nischalshrestha,项目名称:recognize,代码行数:93,代码来源:recognize.py


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