Skip to content

Commit 00174cb

Browse files
authored
Merge pull request #47 from Nebuchadrezzar/django_42
Addressing issue #46: Update for django 4.2
2 parents d7fc51d + c9ee2a3 commit 00174cb

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ Imagefit is a resize service, therefore include its urls.
9999
Prefix it with whatever you want (here "imagefit" for example):
100100

101101
```python
102+
from django.urls import re_path
103+
102104
urlpatterns = urlpatterns('',
103105
104-
url(r'^imagefit/', include('imagefit.urls')),
106+
re_path(r'^imagefit/', include('imagefit.urls')),
105107
)
106108
```
107109

imagefit/conf.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
import tempfile
55
import os
6-
settings.configure()
6+
if not settings.configured:
7+
settings.configure()
8+
79

810
class ImagefitConf(AppConf):
911

imagefit/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def is_cached(self):
5151
def resize(self, width=None, height=None):
5252
return self.pil.thumbnail(
5353
(int(width), int(height)),
54-
PilImage.ANTIALIAS)
54+
PilImage.LANCZOS)
5555

5656
def crop(self, width=None, height=None):
5757
img_w, img_h = self.pil.size

imagefit/views.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from django.core.cache import caches
44
from django.utils.http import http_date
55
from django.views.static import was_modified_since
6+
from inspect import Signature
7+
68

79
from imagefit.conf import settings
810
from imagefit.models import Image, Presets
@@ -11,6 +13,7 @@
1113
import stat
1214
import time
1315

16+
1417
cache = caches[settings.IMAGEFIT_CACHE_BACKEND_NAME]
1518

1619

@@ -40,11 +43,21 @@ def resize(request, path_name, format, url):
4043
if not os.path.exists(path):
4144
return HttpResponse(status=404)
4245
image = Image(path=path)
43-
4446
statobj = os.stat(image.path)
45-
if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
46-
statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]):
47-
return HttpResponseNotModified(content_type=image.mimetype)
47+
48+
# django.views.static.was_modified_since dropped its size argument in 4.1.
49+
sig = Signature(was_modified_since)
50+
51+
if not sig.parameters.get('size'):
52+
if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
53+
statobj[stat.ST_MTIME]):
54+
return HttpResponseNotModified(content_type=image.mimetype)
55+
56+
if sig.parameters.get('size'):
57+
if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
58+
statobj[stat.ST_MTIME],
59+
statobj[stat.ST_SIZE]):
60+
return HttpResponseNotModified(content_type=image.mimetype)
4861

4962
image.cached_name = request.META.get('PATH_INFO')
5063

0 commit comments

Comments
 (0)