mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
Fixed a ValueError that happened when trying to save a Category that has a thumbnail
This commit is contained in:
parent
5b230ef4f5
commit
53b92f3f0f
4 changed files with 25 additions and 6 deletions
|
|
@ -1,3 +1,4 @@
|
|||
from django.core.files.images import get_image_dimensions
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import models
|
||||
from django.utils.encoding import force_text
|
||||
|
|
@ -81,12 +82,7 @@ class Category(CategoryBase):
|
|||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.thumbnail:
|
||||
from django.core.files.images import get_image_dimensions
|
||||
import django
|
||||
if django.VERSION[1] < 2:
|
||||
width, height = get_image_dimensions(self.thumbnail.file)
|
||||
else:
|
||||
width, height = get_image_dimensions(self.thumbnail.file, close=True)
|
||||
width, height = get_image_dimensions(self.thumbnail.file)
|
||||
else:
|
||||
width, height = None, None
|
||||
|
||||
|
|
|
|||
BIN
categories/tests/test_image.jpg
Normal file
BIN
categories/tests/test_image.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.3 KiB |
21
categories/tests/test_models.py
Normal file
21
categories/tests/test_models.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import os
|
||||
|
||||
from django.core.files import File
|
||||
from django.core.files.uploadedfile import UploadedFile
|
||||
|
||||
from categories.models import Category
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class TestCategoryThumbnail(TestCase):
|
||||
|
||||
def test_thumbnail(self):
|
||||
|
||||
file_name = 'test_image.jpg'
|
||||
|
||||
with open(os.path.join(os.path.dirname(__file__), file_name), 'rb') as f:
|
||||
test_image = UploadedFile(File(f), content_type='image/jpeg')
|
||||
category = Category.objects.create(name='Test Category', slug='test-category', thumbnail=test_image)
|
||||
self.assertEqual(category.pk, 1)
|
||||
self.assertEqual(category.thumbnail_width, 640)
|
||||
self.assertEqual(category.thumbnail_height, 480)
|
||||
2
tox.ini
2
tox.ini
|
|
@ -11,6 +11,8 @@ deps=
|
|||
django19: Django==1.9.2
|
||||
django18: Django==1.8.9
|
||||
coverage==4.0.3
|
||||
pillow
|
||||
ipdb
|
||||
-r{toxinidir}/requirements.txt
|
||||
|
||||
commands=
|
||||
|
|
|
|||
Loading…
Reference in a new issue