コード例 #1
0
    def image_url(self):
        """
        Returns the URL to the thumbnail generated for the first public image
        attached to this report or None.

        If the thumbnail doesn't exist, it is created
        """
        for image in itertools.chain(self.image_set.all(), *(comment.image_set.all() for comment in self.comment_set.all())):
            if image.visibility == image.PUBLIC:
                output_path = os.path.join(settings.MEDIA_ROOT, "generated_thumbnails", str(image.pk) + ".png")
                if not os.path.exists(output_path):
                    resize_image(image.image.path, output_path, width=64, height=64)
                return settings.MEDIA_URL + os.path.relpath(output_path, settings.MEDIA_ROOT)

        return None
コード例 #2
0
    def save(self, *args, **kwargs):
        """
        Save the form, and set the password, if it has been set
        """
        password = self.cleaned_data.pop("password", None)
        if password is not None:
            self.instance.set_password(password)

        instance = super().save(*args, **kwargs)

        # if we got a new photo resize it and convert it to a png
        if self.cleaned_data.get("photo"):
            output_path = instance.photo.path + ".png"
            resize_image(instance.photo.path, output_path, width=256, height=256)
            self.instance.photo = instance.photo.name + ".png"
            self.instance.save()

        return instance
コード例 #3
0
    def save(self, *args, **kwargs):
        """
        Save the form, and set the password, if it has been set
        """
        password = self.cleaned_data.pop("password", None)
        if password is not None:
            self.instance.set_password(password)

        instance = super().save(*args, **kwargs)

        # if we got a new photo resize it and convert it to a png
        if self.cleaned_data.get("photo"):
            output_path = instance.photo.path + ".png"
            resize_image(instance.photo.path,
                         output_path,
                         width=256,
                         height=256)
            self.instance.photo = instance.photo.name + ".png"
            self.instance.save()

        return instance
コード例 #4
0
    def image_url(self):
        """
        Returns the URL to the thumbnail generated for the first public image
        attached to this report or None.

        If the thumbnail doesn't exist, it is created
        """
        for image in itertools.chain(
                self.image_set.all(),
                *(comment.image_set.all()
                  for comment in self.comment_set.all())):
            if image.visibility == image.PUBLIC:
                output_path = os.path.join(settings.MEDIA_ROOT,
                                           "generated_thumbnails",
                                           str(image.pk) + ".png")
                if not os.path.exists(output_path):
                    resize_image(image.image.path,
                                 output_path,
                                 width=64,
                                 height=64)
                return settings.MEDIA_URL + os.path.relpath(
                    output_path, settings.MEDIA_ROOT)

        return None