Skip to content

Commit

Permalink
feat: Add django 5.0 support (#1424)
Browse files Browse the repository at this point in the history
* Fix #1377

* feat: Django 5.0 compat

* fix github codecov action

* Add tests for action forms.

* Update test

* Remove legacy code, update language files

* Update *.mo

* Update comment

* get_storage_class removed in Django 5
  • Loading branch information
fsbraun authored Sep 22, 2023
1 parent c3ab24b commit 69893eb
Show file tree
Hide file tree
Showing 70 changed files with 2,900 additions and 3,069 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ jobs:
django-4.0.txt,
django-4.1.txt,
django-4.2.txt,
django-5.0.txt,
]
exclude:
- requirements-file: django-5.0.txt
python-version: 3.8
- requirements-file: django-5.0.txt
python-version: 3.9
os: [
ubuntu-20.04,
]
Expand Down
1 change: 0 additions & 1 deletion filer/admin/clipboardadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ClipboardItemInline(admin.TabularInline):
class ClipboardAdmin(admin.ModelAdmin):
model = Clipboard
inlines = [ClipboardItemInline]
filter_horizontal = ('files',)
raw_id_fields = ('user',)
verbose_name = "DEBUG Clipboard"
verbose_name_plural = "DEBUG Clipboards"
Expand Down
1 change: 0 additions & 1 deletion filer/admin/folderadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,6 @@ def resize_images(self, request, files_queryset, folders_queryset):
"breadcrumbs_action": _("Resize images"),
"to_resize": to_resize,
"resize_form": form,
"cmsplugin_enabled": 'cmsplugin_filer_image' in django_settings.INSTALLED_APPS,
"files_queryset": files_queryset,
"folders_queryset": folders_queryset,
"perms_lacking": perms_needed,
Expand Down
52 changes: 27 additions & 25 deletions filer/admin/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms
from django.conf import settings
from django.contrib.admin import widgets
from django.contrib.admin.helpers import AdminForm
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import gettext as _
Expand All @@ -9,18 +9,18 @@
from ..utils.files import get_valid_filename


class AsPWithHelpMixin:
def as_p_with_help(self):
"Returns this form rendered as HTML <p>s with help text formated for admin."
return self._html_output(
normal_row='<p%(html_class_attr)s>%(label)s %(field)s</p>%(help_text)s',
error_row='%s',
row_ender='</p>',
help_text_html='<p class="help">%s</p>',
errors_on_separate_row=True)
class WithFieldsetMixin:
def get_fieldsets(self):
return getattr(self, "fieldsets", [
(None, {"fields": [field for field in self.fields]})
])

def admin_form(self):
"Returns a class contains the Admin fieldset to show form as admin form"
return AdminForm(self, self.get_fieldsets(), {})

class CopyFilesAndFoldersForm(forms.Form, AsPWithHelpMixin):

class CopyFilesAndFoldersForm(forms.Form):
suffix = forms.CharField(required=False, help_text=_("Suffix which will be appended to filenames of copied files."))
# TODO: We have to find a way to overwrite files with different storage backends first.
# overwrite_files = forms.BooleanField(required=False, help_text=_("Overwrite a file if there already exists a file with the same filename?"))
Expand All @@ -32,7 +32,7 @@ def clean_suffix(self):
return self.cleaned_data['suffix']


class RenameFilesForm(forms.Form, AsPWithHelpMixin):
class RenameFilesForm(WithFieldsetMixin, forms.Form):
rename_format = forms.CharField(required=True)

def clean_rename_format(self):
Expand All @@ -55,24 +55,26 @@ def clean_rename_format(self):
return self.cleaned_data['rename_format']


class ResizeImagesForm(forms.Form, AsPWithHelpMixin):
if 'cmsplugin_filer_image' in settings.INSTALLED_APPS:
thumbnail_option = models.ForeignKey(
ThumbnailOption,
null=True,
blank=True,
verbose_name=_("thumbnail option"),
on_delete=models.CASCADE,
).formfield()
class ResizeImagesForm(WithFieldsetMixin, forms.Form):
fieldsets = ((None, {"fields": (
"thumbnail_option",
("width", "height"),
("crop", "upscale"))}),)

thumbnail_option = models.ForeignKey(
ThumbnailOption,
null=True,
blank=True,
verbose_name=_("thumbnail option"),
on_delete=models.CASCADE,
).formfield()

width = models.PositiveIntegerField(_("width"), null=True, blank=True).formfield(widget=widgets.AdminIntegerFieldWidget)
height = models.PositiveIntegerField(_("height"), null=True, blank=True).formfield(widget=widgets.AdminIntegerFieldWidget)
crop = models.BooleanField(_("crop"), default=True).formfield()
upscale = models.BooleanField(_("upscale"), default=True).formfield()

def clean(self):
if not (self.cleaned_data.get('thumbnail_option') or ((self.cleaned_data.get('width') or 0) + (self.cleaned_data.get('height') or 0))):
if 'cmsplugin_filer_image' in settings.INSTALLED_APPS:
raise ValidationError(_('Thumbnail option or resize parameters must be choosen.'))
else:
raise ValidationError(_('Resize parameters must be choosen.'))
raise ValidationError(_('Thumbnail option or resize parameters must be choosen.'))
return self.cleaned_data
Loading

0 comments on commit 69893eb

Please sign in to comment.