mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Added get_willow_image method to Image
This commit is contained in:
parent
4a804967d9
commit
f1ebd96c1d
@ -4,6 +4,7 @@ import re
|
||||
from six import BytesIO, text_type
|
||||
|
||||
from taggit.managers import TaggableManager
|
||||
from willow.image import Image as WillowImage
|
||||
|
||||
from django.core.files import File
|
||||
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
|
||||
@ -80,6 +81,13 @@ class AbstractImage(models.Model, TagSearchable):
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
def get_willow_image(self):
|
||||
image_file = self.file.file
|
||||
image_file.open('rb')
|
||||
image_file.seek(0)
|
||||
|
||||
return WillowImage.open(image_file)
|
||||
|
||||
def get_rect(self):
|
||||
return Rect(0, 0, self.width, self.height)
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import unittest
|
||||
from willow.image import Image as WillowImage
|
||||
|
||||
from django.test import TestCase
|
||||
from django.core.urlresolvers import reverse
|
||||
@ -268,6 +269,19 @@ class TestGetUsage(TestCase):
|
||||
self.assertTrue(issubclass(Page, type(self.image.get_usage()[0])))
|
||||
|
||||
|
||||
def TestGetWillowImage(TestCase):
|
||||
def setUp(self):
|
||||
self.image = Image.objects.create(
|
||||
title="Test image",
|
||||
file=get_test_image_file(),
|
||||
)
|
||||
|
||||
def test_willow_image_object_returned(self):
|
||||
willow_image = self.image.get_willow_image()
|
||||
|
||||
self.assertIsInstance(willow_image, WillowImage)
|
||||
|
||||
|
||||
class TestIssue573(TestCase):
|
||||
"""
|
||||
This tests for a bug which causes filename limit on Renditions to be reached
|
||||
|
Loading…
Reference in New Issue
Block a user