Skip to content

Commit

Permalink
Merge branch 'master' into fix/js-int-overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun authored Sep 26, 2023
2 parents 62f021f + 72e2d41 commit 9bbce38
Show file tree
Hide file tree
Showing 73 changed files with 2,904 additions and 3,073 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
5 changes: 3 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
CHANGELOG
=========

unpublished
===========
unreleased
==========

* Fixed two more instances of javascript int overflow issue (#1335)
* fix: ensure uniqueness of icon admin url names

3.0.6 (2023-09-08)
==================
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
2 changes: 1 addition & 1 deletion filer/admin/fileadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get_urls(self):
return super().get_urls() + [
path("icon/<int:file_id>/<int:size>",
self.admin_site.admin_view(self.icon_view),
name="filer_file_fileicon")
name=f"filer_{self.model._meta.model_name}_fileicon")
]

def icon_view(self, request, file_id: int, size: int) -> HttpResponse:
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 9bbce38

Please sign in to comment.