|
3 | 3 | from django.core.cache import caches
|
4 | 4 | from django.utils.http import http_date
|
5 | 5 | from django.views.static import was_modified_since
|
| 6 | +from inspect import Signature |
| 7 | + |
6 | 8 |
|
7 | 9 | from imagefit.conf import settings
|
8 | 10 | from imagefit.models import Image, Presets
|
|
11 | 13 | import stat
|
12 | 14 | import time
|
13 | 15 |
|
| 16 | + |
14 | 17 | cache = caches[settings.IMAGEFIT_CACHE_BACKEND_NAME]
|
15 | 18 |
|
16 | 19 |
|
@@ -40,11 +43,21 @@ def resize(request, path_name, format, url):
|
40 | 43 | if not os.path.exists(path):
|
41 | 44 | return HttpResponse(status=404)
|
42 | 45 | image = Image(path=path)
|
43 |
| - |
44 | 46 | 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) |
48 | 61 |
|
49 | 62 | image.cached_name = request.META.get('PATH_INFO')
|
50 | 63 |
|
|
0 commit comments