Skip to content

Commit 7ab5565

Browse files
authored
Merge branch 'django-cms:master' into master
2 parents 48e16a6 + cce13d2 commit 7ab5565

File tree

5 files changed

+62
-10
lines changed

5 files changed

+62
-10
lines changed

CHANGELOG.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22
CHANGELOG
33
=========
44

5-
3.1.3 (2025-05-17)
5+
3.1.4 (2024-07-15)
6+
==================
7+
8+
* feat: Accept new `STORAGES` setting, introduced in Django 4.2 by @fsbraun in https://github.com/django-cms/django-filer/pull/1472
9+
* feat: Replace `render` with `TemplateResponse` in admin views by @fsbraun in https://github.com/django-cms/django-filer/pull/1473
10+
* fix: File expand url incorrect and worked not with custom image models by @fsbraun in https://github.com/django-cms/django-filer/pull/1471
11+
* fix: Crash when moving files from a filtered directory listing by @W1ldPo1nter in https://github.com/django-cms/django-filer/pull/1482
12+
* ci: pre-commit autoupdate by @pre-commit-ci in https://github.com/django-cms/django-filer/pull/1477
13+
14+
15+
3.1.3 (2024-05-17)
616
==================
717
* Fix: Folder select widget did not render correctly with standard Django admin
818
styles.
919

10-
3.1.2 (2025-05-17)
20+
3.1.2 (2024-05-17)
1121
==================
1222

1323
* Made the filer check command compatible with custom image models.

filer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
8. Publish the release and it will automatically release to pypi
1414
"""
1515

16-
__version__ = '3.1.3'
16+
__version__ = '3.1.4'

filer/admin/folderadmin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,13 @@ def directory_listing(self, request, folder_id=None, viewtype=None):
321321
order_by = request.GET.get('order_by', None)
322322
order_by_annotation = None
323323
if order_by is None:
324-
file_qs = file_qs.annotate(coalesce_sort_field=Coalesce(
324+
order_by_annotation = Lower(Coalesce(
325325
Case(
326326
When(name__exact='', then=None),
327327
When(name__isnull=False, then='name')
328328
),
329329
'original_filename'
330330
))
331-
order_by_annotation = Lower('coalesce_sort_field')
332331

333332
order_by = order_by.split(',') if order_by else []
334333
order_by = [field for field in order_by

filer/models/abstract.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import logging
22

33
from django.conf import settings
4+
from django.core.checks import Warning, register as register_check
45
from django.core.exceptions import ValidationError
56
from django.db import models
67
from django.utils.functional import cached_property
78
from django.utils.translation import gettext_lazy as _
89

10+
911
import easy_thumbnails.utils
1012
from easy_thumbnails.VIL import Image as VILImage
1113
from PIL.Image import MAX_IMAGE_PIXELS
@@ -24,10 +26,24 @@
2426
# as if we allow it, it will fail while thumbnailing (first in the admin thumbnails
2527
# and then in the page itself.
2628
# Refer this https://github.com/python-pillow/Pillow/blob/b723e9e62e4706a85f7e44cb42b3d838dae5e546/src/PIL/Image.py#L3148
27-
FILER_MAX_IMAGE_PIXELS = min(
28-
getattr(settings, "FILER_MAX_IMAGE_PIXELS", MAX_IMAGE_PIXELS),
29-
MAX_IMAGE_PIXELS,
30-
)
29+
FILER_MAX_IMAGE_PIXELS = getattr(settings, "FILER_MAX_IMAGE_PIXELS", MAX_IMAGE_PIXELS)
30+
if MAX_IMAGE_PIXELS is not None:
31+
FILER_MAX_IMAGE_PIXELS = min(FILER_MAX_IMAGE_PIXELS, MAX_IMAGE_PIXELS)
32+
33+
34+
@register_check()
35+
def max_pixel_setting_check(app_configs, **kwargs):
36+
if not FILER_MAX_IMAGE_PIXELS:
37+
return [
38+
Warning(
39+
"Both settings.FILER_MAX_IMAGE_PIXELS and PIL.Image.MAX_IMAGE_PIXELS are not set.",
40+
hint="Set FILER_MAX_IMAGE_PIXELS to a positive integer value in your settings.py. "
41+
"This setting is used to limit the maximum number of pixels an image can have "
42+
"to protect your site from memory bombs.",
43+
obj=settings,
44+
)
45+
]
46+
return []
3147

3248

3349
class BaseImage(File):
@@ -130,7 +146,7 @@ def clean(self):
130146
# the image gets attached to a folder and saved. We also
131147
# send the error msg in the JSON and also post the message
132148
# so that they know what is wrong with the image they uploaded
133-
if not self.file:
149+
if not self.file or not FILER_MAX_IMAGE_PIXELS:
134150
return
135151

136152
if self._width is None or self._height is None:

tests/test_admin.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,33 @@ def test_filer_ajax_decompression_bomb(self):
565565

566566
abstract.FILER_MAX_IMAGE_PIXELS = DEFAULT_MAX_IMAGE_PIXELS
567567

568+
def test_filer_max_pixel_deactivation(self):
569+
from django.core.checks import Warning
570+
571+
DEFAULT_MAX_IMAGE_PIXELS = abstract.FILER_MAX_IMAGE_PIXELS
572+
abstract.FILER_MAX_IMAGE_PIXELS = None # Deactivate
573+
574+
self.assertEqual(Image.objects.count(), 0)
575+
folder = Folder.objects.create(name='foo')
576+
with open(self.filename, 'rb') as fh:
577+
file_obj = django.core.files.File(fh)
578+
url = reverse(
579+
'admin:filer-ajax_upload',
580+
kwargs={'folder_id': folder.pk}
581+
) + '?filename=%s' % self.image_name
582+
self.client.post(
583+
url,
584+
data=file_obj.read(),
585+
content_type='image/jpeg',
586+
**{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}
587+
)
588+
self.assertEqual(Image.objects.count(), 1) # Success
589+
check_result = abstract.max_pixel_setting_check(None)
590+
self.assertEqual(len(check_result), 1)
591+
self.assertIsInstance(check_result[0], Warning)
592+
593+
abstract.FILER_MAX_IMAGE_PIXELS = DEFAULT_MAX_IMAGE_PIXELS
594+
568595
def test_filer_ajax_upload_file_using_content_type(self):
569596
self.assertEqual(Image.objects.count(), 0)
570597
folder = Folder.objects.create(name='foo')

0 commit comments

Comments
 (0)