コード例 #1
0
	def _serve_image_error(self, error, error_code=200):
		"""
		Serves an error image.
		
		@param error: Can be a String, Twisted Failure object, or errors.* object.
		
		@param error_code: HTTP Return code. Defaults to 500, internal server error.
		@type error_code: Integer
		"""

		@stack
		def store_error_image(data):
			if self.size in display_sizes and aztk_config.is_production():
				self.log.debug("Storing error image for size: %s" % self.size)
				self.error_images[self.size] = data
			return data

		if self.size in self.error_images.keys() and aztk_config.is_production():
			d = Deferred()
			self.log.debug("serving cached error image for size: %s" % self.size)
			d.callback(self.error_images[self.size])
		else:
			if self.size in display_sizes:
				crop = display_sizes[self.size]['fit_size']
				width = display_sizes[self.size]['width']
				height = display_sizes[self.size]['height']
			elif self.size == CUSTOM:
				width = self.width
				height = self.height
				crop = self.crop
			else:
				width = 500
				height = 500
				crop = False
			
			quality = 80
			if not aztk_config.is_production():
				d = manip.annotate(self.failure_image, 20, 20, '[%s]\n%s' % (self.app.host, str(error)))
			else:
				d = Deferred()
				d.callback(self.failure_image)
			if crop:
				d.addCallback(manip.resize_crop, width, height, quality)
			else:
				d.addCallback(manip.resize_no_crop, width, height, quality)
			d.addCallback(store_error_image)
		self.log.warning('Error Serving Image[%s]: %s' % (self.media_id, str(error)))
		d.addCallback(self._serve_image_content, error_code, cache=False)
		return d
コード例 #2
0
		def store_error_image(data):
			if self.size in display_sizes and aztk_config.is_production():
				self.log.debug("Storing error image for size: %s" % self.size)
				self.error_images[self.size] = data
			return data