示例#1
0
    def create_image(self, user, wall, image_file, x, y):
        """
        Create list of images
        :param user: User instance
        :param wall: Wall instance
        :param image_file: image file instance
        :param x: X coordinate
        :param y: Y coordinate
        """
        self.check_is_upload_allowed(wall_id=wall.id)
        image = WallImage()
        try:
            image = WallImage()
            self.__update_image_system_data(user, image, wall, image_file)

            base_z = WallImage.objects.filter(wall=wall).aggregate(Max('z')).values().pop() or 0

            image.z = base_z + 1
            image.x = x
            image.y = y

            image.width = self.DEFAULT_WIDTH
            image.height = self.DEFAULT_HEIGHT
#            print "Init: %sx%s" % (str(image.width), str(image.height))
            image.save()

            image.width, image.height = self._get_geometry(image.image_file)
#            print "Geometry: %sx%s" % (str(image.width), str(image.height))

            self._add_dynamics(image)
            image.width = image.thumbnail.width
            image.height = image.thumbnail.height
#            print "Th: %sx%s" % (str(image.width), str(image.height))
            image.save()
        except IOError, e:
            # This is the broken image case
            # delete should also remove the file?
            image.delete()
            raise e