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: Replace render with TemplateResponse in admin views #1473

Merged
merged 1 commit into from
May 20, 2024
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
15 changes: 8 additions & 7 deletions filer/admin/folderadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from django.db.models import Case, F, OuterRef, Subquery, When
from django.db.models.functions import Coalesce, Lower
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
from django.urls import path, reverse
from django.utils.encoding import force_str
from django.utils.html import escape, format_html
Expand Down Expand Up @@ -480,7 +481,7 @@ def directory_listing(self, request, folder_id=None, viewtype=None):
'enable_permissions': settings.FILER_ENABLE_PERMISSIONS,
'can_make_folder': request.user.is_superuser or (folder.is_root and settings.FILER_ALLOW_REGULAR_USERS_TO_ADD_ROOT_FOLDERS) or permissions.get("has_add_children_permission"),
})
return render(request, self.directory_listing_template, context)
return TemplateResponse(request, self.directory_listing_template, context)

def filter_folder(self, qs, terms=()):
# Source: https://github.com/django/django/blob/1.7.1/django/contrib/admin/options.py#L939-L947 flake8: noqa
Expand Down Expand Up @@ -814,7 +815,7 @@ def delete_files_or_folders(self, request, files_queryset, folders_queryset):
})

# Display the destination folder selection page
return render(
return TemplateResponse(
request,
"admin/filer/delete_selected_files_confirmation.html",
context
Expand Down Expand Up @@ -954,7 +955,7 @@ def move_files_and_folders(self, request, files_queryset, folders_queryset):
})

# Display the destination folder selection page
return render(request, "admin/filer/folder/choose_move_destination.html", context)
return TemplateResponse(request, "admin/filer/folder/choose_move_destination.html", context)

move_files_and_folders.short_description = _("Move selected files and/or folders")

Expand Down Expand Up @@ -1037,7 +1038,7 @@ def rename_files(self, request, files_queryset, folders_queryset):
})

# Display the rename format selection page
return render(request, "admin/filer/folder/choose_rename_format.html", context)
return TemplateResponse(request, "admin/filer/folder/choose_rename_format.html", context)

rename_files.short_description = _("Rename files")

Expand Down Expand Up @@ -1169,7 +1170,7 @@ def copy_files_and_folders(self, request, files_queryset, folders_queryset):
})

# Display the destination folder selection page
return render(request, "admin/filer/folder/choose_copy_destination.html", context)
return TemplateResponse(request, "admin/filer/folder/choose_copy_destination.html", context)

copy_files_and_folders.short_description = _("Copy selected files and/or folders")

Expand Down Expand Up @@ -1298,6 +1299,6 @@ def resize_images(self, request, files_queryset, folders_queryset):
})

# Display the resize options page
return render(request, "admin/filer/folder/choose_images_resize_options.html", context)
return TemplateResponse(request, "admin/filer/folder/choose_images_resize_options.html", context)

resize_images.short_description = _("Resize selected images")
13 changes: 9 additions & 4 deletions filer/admin/imageadmin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django import forms
from django.shortcuts import get_object_or_404, render
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
from django.urls import path
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy
Expand Down Expand Up @@ -95,9 +96,13 @@ def get_urls(self):

def expand_view(self, request, file_id):
image = get_object_or_404(self.model, pk=file_id)
return render(request, "admin/filer/image/expand.html", context={
"original_url": image.url
})
return TemplateResponse(
request,
"admin/filer/image/expand.html",
context={
"original_url": image.url
},
)


if FILER_IMAGE_MODEL == 'filer.Image':
Expand Down
6 changes: 3 additions & 3 deletions filer/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.exceptions import PermissionDenied
from django.http import HttpResponseRedirect
from django.http.response import HttpResponseBadRequest
from django.shortcuts import render
from django.template.response import TemplateResponse
from django.utils.translation import gettext_lazy as _

from .. import settings as filer_settings
Expand Down Expand Up @@ -58,7 +58,7 @@ def make_folder(request, folder_id=None):
new_folder.parent = folder
new_folder.owner = request.user
new_folder.save()
return render(request, 'admin/filer/dismiss_popup.html', context)
return TemplateResponse(request, 'admin/filer/dismiss_popup.html', context)
else:
new_folder_form = NewFolderForm()

Expand All @@ -69,7 +69,7 @@ def make_folder(request, folder_id=None):
'is_popup': popup_status(request),
'filer_admin_context': AdminContext(request),
})
return render(request, 'admin/filer/folder/new_folder_form.html', context)
return TemplateResponse(request, 'admin/filer/folder/new_folder_form.html', context)


@login_required
Expand Down
Loading