Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add django 5.0 support #1424

Merged
merged 17 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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.'))

Check warning on line 79 in filer/admin/forms.py

View check run for this annotation

Codecov / codecov/patch

filer/admin/forms.py#L79

Added line #L79 was not covered by tests
return self.cleaned_data
Loading
Loading