From 52f610e787cef554673e3852ff1e3adeec962886 Mon Sep 17 00:00:00 2001 From: Jonathan Ellenberger Date: Fri, 15 May 2015 10:40:56 -0400 Subject: [PATCH] Fixing OnDiscPlaceholderImage empty file bug #13 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Includes: * Updating tests * Swapping out placeholder.gif for placeholder.png (since PIL doesn’t know how to invert ‘P’ images: https://github.com/python-pillow/Pillow/blob/master/PIL/ImageOps.py#L50) --- .../on-storage-placeholder/placeholder.gif | Bin 1740 -> 0 bytes .../on-storage-placeholder/placeholder.png | Bin 0 -> 3504 bytes tests/models.py | 4 +-- tests/placeholder.gif | Bin 1740 -> 0 bytes tests/placeholder.png | Bin 0 -> 3504 bytes tests/tests.py | 30 +++++++++++------- versatileimagefield/placeholder.py | 10 ++++-- 7 files changed, 28 insertions(+), 16 deletions(-) delete mode 100644 tests/media/on-storage-placeholder/placeholder.gif create mode 100644 tests/media/on-storage-placeholder/placeholder.png delete mode 100644 tests/placeholder.gif create mode 100644 tests/placeholder.png diff --git a/tests/media/on-storage-placeholder/placeholder.gif b/tests/media/on-storage-placeholder/placeholder.gif deleted file mode 100644 index 0cf85e61a579b03f08dc683016e1bb14d016f1be..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1740 zcmV;-1~d6bNk%v~VZs3{0pkDw%*@P|mX^iE#hjd+x3{;kv9Y70qrSers;a6000000 z00000000000000000000EC2ui0Kx$*0RRO45XecZy*TU5yZ>M)j$~<`XsWJk>%MR- z&vb3yc&_h!@BhG{a7Zi~kI1BQ$!t2G(5Q4uty-_xtai)odcWYXcuX#v&*-#z&2GEj z@VIs;jK6uCK7Mva__cwzs&sy1Tr+zQ4f1!o$SH#>dFX%FE2n&d<=%($mz{*4NnC z+S}aS-rwNi;^XAy=I7|?>g(+7?(gvN^7Hid_V@Vt`uqI-{{H|23LHqVpuvL(6DnND zu%W|;5F<*QNU@^Dix@L%+{m$`$B+IXLy8oJq5$&6_xL z>fFh*r_Y~2g9;r=w5ZXeNRujE%CxD|r%}R)+}%ufzy<*ZI2TZ2S#$@`ra7SAJi4R+y9hLM-t0MpfX19-9|=7>fNtBkH~+?P zyZ7*r2<$?x(EDy}47_`{CK6q`hU%%IHxDo!XeOEyWtlO%ow;gS~gc$!@w0uWqYLJaoSd#}~?VVQJw`DF!YdT7C# z9TnGE2U>DK<%%X^XvBa$-f6*&Kq6@uo-yj#5rl+-s9*>XzSpRa;#Ck_getV@TLq6| zy59tuQqXBemV(Knf(I0UKmi2gm}gxVsQAHV4pKSS3RDt#V*srVYNK7b)|F^Qw`PXh zkrIg4o&h;Z>7-p){$9A@t+T3todwEH$t(rcPEhMcRO+^9mfOwsE1Ya{`RZm9Od2f; z5UN?1s1#V*9l7zEt5J(>5(_}MGhRUN1eWUCDtXsZIbXApk%t|;>ArhGz!dx|0mK=N z*jm2MhRblV4l8P52*Je$D7%~?>+xJ0bNsQ&C}(_WMmq-iEpy^!CcubQ(!8?Ha|xWm zh?XM!0farvwlf7G*17M@6lX2Qmw`-YEAx;gOd4nlJqj-<@e?S&ZSTIbDngI9_8K<{IOqIAw$;0+>jd3b0C+{w zOCLgypGuJa2kJT&L-^`%>Z$w>(jPyH(3g*^1$(7TI_1N=UIpL>0-`CY1P7RpcIIR) zU;T+!4HV$6%m*y^hQOi(IW8T~>SDh|#U~9Y6QnozUJRAlPN+hWhmE6TZ@qKSq{R%e$s6rRY(1tqnp%9IzM29Cz z(TZC1q8QDnMmNgQj(YT?APuQVM@rI?n)IY7O{q#(%F>p)^rbM3sZ3`|)0*1!rZ~;1 zPIt=Fp8E8sKn+)v8+cs#wjcR=3L4u6p&W iU=6ES$4b_+n)R$`O{-eh%GS2J^{sG?t6WzS0RTI|(rr8d diff --git a/tests/media/on-storage-placeholder/placeholder.png b/tests/media/on-storage-placeholder/placeholder.png new file mode 100644 index 0000000000000000000000000000000000000000..3c49a7fd4bd2623f69b0e43e7cde988d43ebffbd GIT binary patch liter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4zmM?ASo5$0a^2PZl<{2Zj2E~Ypaj~N$ z-ftwaIsF?lySwy+gddj9Pi<%$x$(A5Gu<#*9SYpxs2_cijd1Ib;=TM;4P?u)D`BLf zYlN$*_JpN6|31Ad1I=i!$EncF@dI7bvh3eV+IerIMzk}1YB7?@0Dg{QVEHe6nGl&%xD^YSDQ6>#pEF>J86=wny3q*q&LOYpq3=*HbG^)5>mvajs-w`kA$A zlk?ESm4xHf<~o@KdEt%I+#*u*WtmK7pL71)MfOC+1h-reEfywvMchpzxZi9jmSsgk zXFRD^Q6(=5U93T8)YE8i63f$?`2(#L?18wBIm+W+d6-%_R>iMwu;52R$zuz$YYuO~ zB8?=gTg+(}s%Fj0sO3c!X$IM8srPg_+k!fuwJ`ISvG z%0XY{2!0PHVQn5>Ov*5f2e%>i+a9?R*4OBbRd*fPVtL;J-i-e#tNtg*{%P0o345GR o-Aw$SJF<;xJ+hdqfha-_T-W}?Z7fB$_6_A^=W2WR@Ts%^0qpJOO#lD@ literal 0 HcmV?d00001 diff --git a/tests/models.py b/tests/models.py index 07fc5d8..ef70e01 100644 --- a/tests/models.py +++ b/tests/models.py @@ -37,7 +37,7 @@ class VersatileImageTestModel(models.Model): placeholder_image=OnDiscPlaceholderImage( path=os.path.join( os.path.dirname(os.path.abspath(__file__)), - 'placeholder.gif' + 'placeholder.png' ) ) ) @@ -45,7 +45,7 @@ class VersatileImageTestModel(models.Model): upload_to='./', blank=True, placeholder_image=OnStoragePlaceholderImage( - path='on-storage-placeholder/placeholder.gif' + path='on-storage-placeholder/placeholder.png' ) ) optional_image_3 = VersatileImageField( diff --git a/tests/placeholder.gif b/tests/placeholder.gif deleted file mode 100644 index 0cf85e61a579b03f08dc683016e1bb14d016f1be..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1740 zcmV;-1~d6bNk%v~VZs3{0pkDw%*@P|mX^iE#hjd+x3{;kv9Y70qrSers;a6000000 z00000000000000000000EC2ui0Kx$*0RRO45XecZy*TU5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NgQj(YT?APuQVM@rI?n)IY7O{q#(%F>p)^rbM3sZ3`|)0*1!rZ~;1 zPIt=Fp8E8sKn+)v8+cs#wjcR=3L4u6p&W iU=6ES$4b_+n)R$`O{-eh%GS2J^{sG?t6WzS0RTI|(rr8d diff --git a/tests/placeholder.png b/tests/placeholder.png new file mode 100644 index 0000000000000000000000000000000000000000..3c49a7fd4bd2623f69b0e43e7cde988d43ebffbd GIT binary patch literal 3504 zcmb7H2~<;88jhf)RTxfd2MCL#!GdT=On^WFfhs!^P=bIg(GVVxLJ~*<1Z1i96l7ee zBZ7z!N2a8RRgg`DfK#FZflx$5b_K(puoE_!d8kO|9GEk{lf30S|M&gN{olR!r5ts2 zP}!-u69R##I62z7Lm=CJ2mgrA6+ooVWbZ5R0_E6wb4bh}PBeuDKn?{m0|1y4oe~VV z1C+p+hdW;2NnPX(-;K!L}d*e zMhhgsy-bM*iQzUt2+c8;1(0H0J*csvR9qn3+6rdL#e)KLfJ1?C>0t~uo=bqg)5U}L zYcL89duPH4CBWYYhGDTtw23Jei$=gO2hkYRLGXt)LYv@C zv3QIb?85;Ey|Ds=@b0$uAAEsN1b7IC6OKorqNAgc(Z)z7D;R~w;c#mj7>p5UVZ@GM za41|O23v1k!4_asS+sBtjmdzmDN+KMksJaXjP!j9^ze_e4EBdIfdxZxDd8wI^59xZ z>xM+)|2C!5KU%Xn?!ZR8n+mf%V!{EGJHTc}vZ&y|1?jE13dh^901Ai6@?bK<)~k3l zgvnvDLzv+(8xj__k4T}?7;AvxI|h-6cVe(P6b2P=vL(Pl4J3^gh{s~gamI(uaQ4Q= z#%Q#i3C_ga!O?*lh*>sZXUDJ>76y8jB!|=bnZNQs`Rkv?bcq7^k{-?-p@IN(Mh9j&ztl`G%O{isGjnruZ{NPX=2cx)wX!sKV0C3#&Rm%pc$y0GF4-;3jR6gMP7=H<2~aG!+Vaw`eQd6G zcs#1IuO=}%K`tsV!{_ktxc){t@p7^=Klsv2-aJ-U%eV1_KKX}hyX5pY`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zme25Ga#pjlH z5eS4i!Kp^=;KtgEx7{)t&IgaVI=24k^BHni&$94mpIX-C*OEKhT7rL0UvSQ^GPplO ziN2gNuZQhS&C=>M7m+zRO{hMjE-7KkQ;tY0XuBO>i1CyTANaXbZ+GH+4^S!h@CAdd zn}p|{Hy!+{1(6%ilS5IVyu#7tFcC&gB6>Dp-8rFlQ6vU3npL1P2PkhmOjhL_xAtw|$2EK+QSXjKJg5L{4zmM?ASo5$0a^2PZl<{2Zj2E~Ypaj~N$ z-ftwaIsF?lySwy+gddj9Pi<%$x$(A5Gu<#*9SYpxs2_cijd1Ib;=TM;4P?u)D`BLf zYlN$*_JpN6|31Ad1I=i!$EncF@dI7bvh3eV+IerIMzk}1YB7?@0Dg{QVEHe6nGl&%xD^YSDQ6>#pEF>J86=wny3q*q&LOYpq3=*HbG^)5>mvajs-w`kA$A zlk?ESm4xHf<~o@KdEt%I+#*u*WtmK7pL71)MfOC+1h-reEfywvMchpzxZi9jmSsgk zXFRD^Q6(=5U93T8)YE8i63f$?`2(#L?18wBIm+W+d6-%_R>iMwu;52R$zuz$YYuO~ zB8?=gTg+(}s%Fj0sO3c!X$IM8srPg_+k!fuwJ`ISvG z%0XY{2!0PHVQn5>Ov*5f2e%>i+a9?R*4OBbRd*fPVtL;J-i-e#tNtg*{%P0o345GR o-Aw$SJF<;xJ+hdqfha-_T-W}?Z7fB$_6_A^=W2WR@Ts%^0qpJOO#lD@ literal 0 HcmV?d00001 diff --git a/tests/tests.py b/tests/tests.py index 1f3408d..282610c 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -82,7 +82,8 @@ def setUp(self): self.user = user self.client = client - def tearDown(self): + @classmethod + def tearDownClass(cls): """ Deletes files made by VersatileImageFields during tests """ @@ -171,35 +172,42 @@ def test_invert_plus_thumbnail_sizer_filtered_path(self): def test_placeholder_image(self): """Ensures placehold.it integration""" + self.jpg.optional_image.create_on_demand = True self.assertEqual( self.jpg.optional_image.crop['100x100'].url, '/media/__sized__/__placeholder__/' - 'placeholder-crop-c0-5__0-5-100x100.gif' + 'placeholder-crop-c0-5__0-5-100x100.png' ) self.assertEqual( self.jpg.optional_image.thumbnail['100x100'].url, '/media/__sized__/__placeholder__/' - 'placeholder-thumbnail-100x100.gif' + 'placeholder-thumbnail-100x100.png' ) self.assertEqual( self.jpg.optional_image.filters.invert.url, - '/media/__placeholder__/__filtered__/placeholder__invert__.gif' + '/media/__placeholder__/__filtered__/placeholder__invert__.png' ) self.assertEqual( self.jpg.optional_image_2.crop['100x100'].url, '/media/__sized__/__placeholder__/on-storage-placeholder/' - 'placeholder-crop-c0-5__0-5-100x100.gif' + 'placeholder-crop-c0-5__0-5-100x100.png' ) self.assertEqual( self.jpg.optional_image_2.thumbnail['100x100'].url, '/media/__sized__/__placeholder__/on-storage-placeholder/' - 'placeholder-thumbnail-100x100.gif' + 'placeholder-thumbnail-100x100.png' ) self.assertEqual( self.jpg.optional_image_2.filters.invert.url, '/media/__placeholder__/on-storage-placeholder/__filtered__/' - 'placeholder__invert__.gif' + 'placeholder__invert__.png' ) + self.assertFalse( + self.jpg.optional_image.field.storage.size( + self.jpg.optional_image.name + ) is 0 + ) + self.jpg.optional_image.create_on_demand = False def test_setting_ppoi_values(self): """Ensure PPOI values are set correctly""" @@ -571,11 +579,11 @@ def test_horizontal_and_vertical_crop(self): def test_DummyFilter(self): """Tests placeholder image functionality for filters""" - test_jpg = VersatileImageTestModel.objects.get( + test_png = VersatileImageTestModel.objects.get( img_type='png' ) - test_jpg.optional_image.create_on_demand = True - test_jpg.optional_image.filters.invert.url + test_png.optional_image.create_on_demand = True + test_png.optional_image.filters.invert.url def test_crop_and_thumbnail_key_assignment(self): """Tests placeholder image functionality for filters""" @@ -772,7 +780,7 @@ def test_template_rendering(self): - + """ diff --git a/versatileimagefield/placeholder.py b/versatileimagefield/placeholder.py index 15c646f..effe099 100644 --- a/versatileimagefield/placeholder.py +++ b/versatileimagefield/placeholder.py @@ -17,7 +17,11 @@ def __init__(self, file, name): `file` - A python file instance. `name` - The desired filename of `file`. """ - self.image_data = ContentFile(file.read(), name=name) + if isinstance(file, ContentFile): + image_data = file + else: + image_data = ContentFile(file.read(), name=name) + self.image_data = image_data file.close() @@ -33,8 +37,8 @@ def __init__(self, path): """ folder, name = os.path.split(path) file = open(path, 'rb') - self.image_data = ContentFile(file.read(), name=name) - super(OnDiscPlaceholderImage, self).__init__(file, name) + content_file = ContentFile(file.read(), name=name) + super(OnDiscPlaceholderImage, self).__init__(content_file, name) class OnStoragePlaceholderImage(PlaceholderImage):