From 984a45b71654dc5e4b349b076a726aaa96988d86 Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Sun, 19 May 2024 17:59:21 +0200 Subject: [PATCH] fix: pyupgrade to 3.8+ --- filer/admin/fileadmin.py | 2 +- filer/admin/folderadmin.py | 8 +++---- filer/fields/file.py | 2 +- filer/fields/folder.py | 2 +- filer/fields/multistorage_file.py | 2 +- filer/models/clipboardmodels.py | 2 +- filer/models/filemodels.py | 6 ++--- filer/models/thumbnailoptionmodels.py | 2 +- filer/templatetags/filer_tags.py | 2 +- tests/helpers.py | 2 +- tests/test_admin.py | 32 +++++++++++++-------------- tests/test_form_fields.py | 2 +- tests/test_migrations.py | 2 +- tests/test_models.py | 6 ++--- 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/filer/admin/fileadmin.py b/filer/admin/fileadmin.py index c04f9c2e9..48d06442b 100644 --- a/filer/admin/fileadmin.py +++ b/filer/admin/fileadmin.py @@ -192,7 +192,7 @@ def get_model_perms(self, request): def display_canonical(self, instance): canonical = instance.canonical_url if canonical: - return mark_safe('{}'.format(canonical, canonical)) + return mark_safe(f'{canonical}') else: return '-' display_canonical.allow_tags = True diff --git a/filer/admin/folderadmin.py b/filer/admin/folderadmin.py index 203674b55..029964b6c 100644 --- a/filer/admin/folderadmin.py +++ b/filer/admin/folderadmin.py @@ -253,10 +253,10 @@ def directory_listing(self, request, folder_id=None, viewtype=None): self.get_queryset(request).get(id=last_folder_id) except self.model.DoesNotExist: url = reverse('admin:filer-directory_listing-root') - url = "{}{}".format(url, admin_url_params_encoded(request)) + url = f"{url}{admin_url_params_encoded(request)}" else: url = reverse('admin:filer-directory_listing', kwargs={'folder_id': last_folder_id}) - url = "{}{}".format(url, admin_url_params_encoded(request)) + url = f"{url}{admin_url_params_encoded(request)}" return HttpResponseRedirect(url) elif folder_id is None: folder = FolderRoot() @@ -840,7 +840,7 @@ def _format_callback(self, obj, user, admin_site, perms_needed): else: # Don't display link to edit, because it either has no # admin or is edited inline. - return '{}: {}'.format(capfirst(opts.verbose_name), force_str(obj)) + return f'{capfirst(opts.verbose_name)}: {force_str(obj)}' def _check_copy_perms(self, request, files_queryset, folders_queryset): try: @@ -1073,7 +1073,7 @@ def _get_available_name(self, destination, name): count = itertools.count(1) original = name while destination.contains_folder(name): - name = "{}_{}".format(original, next(count)) + name = f"{original}_{next(count)}" return name def _copy_folder(self, folder, destination, suffix, overwrite): diff --git a/filer/fields/file.py b/filer/fields/file.py index ce1e81b6a..11f91774d 100644 --- a/filer/fields/file.py +++ b/filer/fields/file.py @@ -60,7 +60,7 @@ def render(self, name, value, attrs=None, renderer=None): hidden_input = super(ForeignKeyRawIdWidget, self).render(name, value, attrs) # grandparent super context = { 'hidden_input': hidden_input, - 'lookup_url': '{}{}'.format(related_url, lookup_url), + 'lookup_url': f'{related_url}{lookup_url}', 'change_url': change_url, 'object': obj, 'lookup_name': name, diff --git a/filer/fields/folder.py b/filer/fields/folder.py index 715507aaf..d0fbd5707 100644 --- a/filer/fields/folder.py +++ b/filer/fields/folder.py @@ -54,7 +54,7 @@ def render(self, name, value, attrs=None, renderer=None): # API to determine the ID dynamically. context = { 'hidden_input': hidden_input, - 'lookup_url': '{}{}'.format(related_url, url), + 'lookup_url': f'{related_url}{url}', 'lookup_name': name, 'span_id': css_id_description_txt, 'object': obj, diff --git a/filer/fields/multistorage_file.py b/filer/fields/multistorage_file.py index 8ceb76a99..99f730403 100644 --- a/filer/fields/multistorage_file.py +++ b/filer/fields/multistorage_file.py @@ -159,7 +159,7 @@ def value_to_string(self, obj): encoded_string = base64.b64encode(payload_file.read()).decode('utf-8') return value, encoded_string except OSError: - warnings.warn('The payload for "{}" is missing. No such file on disk: {}!'.format(obj.original_filename, self.storage.location)) + warnings.warn(f'The payload for "{obj.original_filename}" is missing. No such file on disk: {self.storage.location}!') return value def to_python(self, value): diff --git a/filer/models/clipboardmodels.py b/filer/models/clipboardmodels.py index 25daebaff..51c4b780e 100644 --- a/filer/models/clipboardmodels.py +++ b/filer/models/clipboardmodels.py @@ -35,7 +35,7 @@ def append_file(self, file_obj): return True def __str__(self): - return "Clipboard {} of {}".format(self.id, self.user) + return f"Clipboard {self.id} of {self.user}" class ClipboardItem(models.Model): diff --git a/filer/models/filemodels.py b/filer/models/filemodels.py index 38f9a98f4..ad77031c2 100644 --- a/filer/models/filemodels.py +++ b/filer/models/filemodels.py @@ -158,9 +158,9 @@ class Meta: def __str__(self): if self.name in ('', None): - text = "{}".format(self.original_filename) + text = f"{self.original_filename}" else: - text = "{}".format(self.name) + text = f"{self.name}" return text @classmethod @@ -312,7 +312,7 @@ def label(self): text = self.original_filename or 'unnamed file' else: text = self.name - text = "{}".format(text) + text = f"{text}" return text def __lt__(self, other): diff --git a/filer/models/thumbnailoptionmodels.py b/filer/models/thumbnailoptionmodels.py index aee18c08e..883df7989 100644 --- a/filer/models/thumbnailoptionmodels.py +++ b/filer/models/thumbnailoptionmodels.py @@ -38,7 +38,7 @@ class Meta: verbose_name_plural = _("thumbnail options") def __str__(self): - return '{} -- {} x {}'.format(self.name, self.width, self.height) + return f'{self.name} -- {self.width} x {self.height}' @property def as_dict(self): diff --git a/filer/templatetags/filer_tags.py b/filer/templatetags/filer_tags.py index 3ceef60a6..faaba6109 100644 --- a/filer/templatetags/filer_tags.py +++ b/filer/templatetags/filer_tags.py @@ -89,7 +89,7 @@ def filesize(bytes, format='auto1024'): unit = '{}{}'.format(base == 1024 and unit.upper() or unit, base == 1024 and 'iB' or 'B') - return '{} {}'.format(bytes, unit) + return f'{bytes} {unit}' if bytes == 0: return bytes diff --git a/tests/helpers.py b/tests/helpers.py index badf241f9..506a367de 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -25,7 +25,7 @@ def create_folder_structure(depth=2, sibling=2, parent=None): depth_range.reverse() for d in depth_range: for s in range(1, sibling + 1): - name = "folder: %s -- %s" % (str(d), str(s)) + name = "folder: {} -- {}".format(str(d), str(s)) folder = Folder(name=name, parent=parent) folder.save() create_folder_structure(depth=d - 1, sibling=sibling, parent=folder) diff --git a/tests/test_admin.py b/tests/test_admin.py index 4aacad7c1..5ab156417 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -629,7 +629,7 @@ def test_filer_ajax_upload_file_error(self): 'admin:filer-ajax_upload', kwargs={ 'folder_id': folder.pk + 1} - ) + '?filename={0}'.format(self.image_name) + ) + f'?filename={self.image_name}' response = self.client.post( url, data=file_obj.read(), @@ -693,7 +693,7 @@ def test_filer_ajax_upload_without_permissions_error(self, extra_headers={}): 'admin:filer-ajax_upload', kwargs={ 'folder_id': folder.pk} - ) + '?filename={0}'.format(self.image_name) + ) + f'?filename={self.image_name}' response = self.client.post( url, data=file_obj.read(), @@ -759,7 +759,7 @@ def test_filer_ajax_upload_permissions_error(self, extra_headers={}): 'admin:filer-ajax_upload', kwargs={ 'folder_id': folder.pk} - ) + '?filename={0}'.format(self.image_name) + ) + f'?filename={self.image_name}' response = self.client.post( url, data=file_obj.read(), @@ -1103,10 +1103,10 @@ def _do_test_rename(self, url, new_name, file_obj=None, folder_obj=None): 'new_name' should be a plain string, no formatting supported. """ if file_obj is not None: - checkbox_name = 'file-{}'.format(file_obj.id) + checkbox_name = f'file-{file_obj.id}' files = [file_obj] elif folder_obj is not None: - checkbox_name = 'folder-{}'.format(folder_obj.id) + checkbox_name = f'folder-{folder_obj.id}' # files inside this folder, non-recursive files = File.objects.filter(folder=folder_obj) else: @@ -1322,9 +1322,9 @@ def test_with_permissions_disabled(self): item_list = response.context['paginated_items'].object_list # user sees all items: FOO, BAR, BAZ, SAMP self.assertEqual( - set(folder.pk for folder in item_list), - set([self.foo_folder.pk, self.bar_folder.pk, self.baz_folder.pk, - self.spam_file.pk])) + {folder.pk for folder in item_list}, + {self.foo_folder.pk, self.bar_folder.pk, self.baz_folder.pk, self.spam_file.pk} + ) def test_folder_ownership(self): with SettingsOverride(filer_settings, FILER_ENABLE_PERMISSIONS=True): @@ -1336,8 +1336,8 @@ def test_folder_ownership(self): # he doesn't see BAR, BAZ and SPAM because he doesn't own them # and no permission has been given self.assertEqual( - set(folder.pk for folder in item_list), - set([self.foo_folder.pk])) + {folder.pk for folder in item_list}, + {self.foo_folder.pk}) def test_with_permission_given_to_folder(self): with SettingsOverride(filer_settings, FILER_ENABLE_PERMISSIONS=True): @@ -1355,8 +1355,8 @@ def test_with_permission_given_to_folder(self): item_list = response.context['paginated_items'].object_list # user sees 2 folder : FOO, BAR self.assertEqual( - set(folder.pk for folder in item_list), - set([self.foo_folder.pk, self.bar_folder.pk])) + {folder.pk for folder in item_list}, + {self.foo_folder.pk, self.bar_folder.pk}) def test_with_permission_given_to_parent_folder(self): with SettingsOverride(filer_settings, FILER_ENABLE_PERMISSIONS=True): @@ -1373,9 +1373,9 @@ def test_with_permission_given_to_parent_folder(self): item_list = response.context['paginated_items'].object_list # user sees all items because he has permissions on the parent folder self.assertEqual( - set(folder.pk for folder in item_list), - set([self.foo_folder.pk, self.bar_folder.pk, self.baz_folder.pk, - self.spam_file.pk])) + {folder.pk for folder in item_list}, + {self.foo_folder.pk, self.bar_folder.pk, self.baz_folder.pk, self.spam_file.pk} + ) def test_search_against_owner(self): url = reverse('admin:filer-directory_listing', @@ -1416,7 +1416,7 @@ def test_search_special_characters(self): # Create a file with a problematic filename problematic_file = django.core.files.base.ContentFile('some data') - filename = u'christopher_eccleston' + filename = 'christopher_eccleston' problematic_file.name = filename self.spam_file = File.objects.create( owner=self.staff_user, original_filename=filename, diff --git a/tests/test_form_fields.py b/tests/test_form_fields.py index f1eda42c5..2d56500d0 100644 --- a/tests/test_form_fields.py +++ b/tests/test_form_fields.py @@ -24,5 +24,5 @@ def test_widget_has_change_button(self): content = widget.render("foo", file.id, {}) self.assertIn( - "/admin/filer/file/{}/change/?_edit_from_widget=1".format(file.id), content + f"/admin/filer/file/{file.id}/change/?_edit_from_widget=1", content ) diff --git a/tests/test_migrations.py b/tests/test_migrations.py index 7a65b508e..0cbc5dffa 100644 --- a/tests/test_migrations.py +++ b/tests/test_migrations.py @@ -27,4 +27,4 @@ def test_for_missing_migrations(self): status_code = '0' if status_code == '1': - self.fail('There are missing migrations:\n {}'.format(output.getvalue())) + self.fail(f'There are missing migrations:\n {output.getvalue()}') diff --git a/tests/test_models.py b/tests/test_models.py index e3c6bb56c..3d52e2502 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -87,19 +87,19 @@ def test_create_icons(self): self.assertEqual(len(icons), len(filer_settings.FILER_ADMIN_ICON_SIZES)) for size in filer_settings.FILER_ADMIN_ICON_SIZES: self.assertEqual(os.path.basename(icons[size]), - file_basename + '__%sx%s_q85_crop_subsampling-2_upscale.jpg' % (size, size)) + file_basename + '__{}x{}_q85_crop_subsampling-2_upscale.jpg'.format(size, size)) def test_access_icons_property(self): """Test IconsMixin that calls static on a non-existent file""" - class CustomObj(IconsMixin, object): + class CustomObj(IconsMixin): _icon = 'custom' custom_obj = CustomObj() try: icons = custom_obj.icons except Exception as e: - self.fail("'.icons' access raised Exception {0} unexpectedly!".format(e)) + self.fail(f"'.icons' access raised Exception {e} unexpectedly!") self.assertEqual(len(icons), len(filer_settings.FILER_ADMIN_ICON_SIZES)) def test_file_upload_public_destination(self):