示例#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
示例#2
0
 def fork_image(self, user, forked_wall, source_image):
     forked_image = WallImage(wall=forked_wall, image_file=source_image.image_file)
     self.__update_image_user_data(forked_image, source_image)
     self.__update_image_system_data(user, forked_image, forked_wall, source_image.image_file)
     forked_image.save()
     return forked_image