Skip to content

Commit

Permalink
Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
NikAzanov committed Sep 11, 2023
1 parent d067121 commit 2711f57
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
8 changes: 6 additions & 2 deletions import_export_extensions/admin/mixins/export_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _redirect_to_export_results_page(
url = f"{url}?{query}"
return HttpResponseRedirect(redirect_to=url)

def has_export_permission(self, request):
def has_export_permission(self, request: WSGIRequest):
"""Return whether a request has export permission."""
EXPORT_PERMISSION_CODE = getattr(
settings,
Expand All @@ -329,7 +329,11 @@ def has_export_permission(self, request):
codename = get_permission_codename(EXPORT_PERMISSION_CODE, opts)
return request.user.has_perm("%s.%s" % (opts.app_label, codename))

def changelist_view(self, request, context=None):
def changelist_view(
self,
request: WSGIRequest,
context: typing.Optional[dict[str, typing.Any]] = None,
):
"""Add the check for permission to changelist template context."""
context = context or {}
context["has_export_permission"] = True
Expand Down
8 changes: 6 additions & 2 deletions import_export_extensions/admin/mixins/import_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def _redirect_to_results_page(

return HttpResponseRedirect(redirect_to=url)

def has_import_permission(self, request):
def has_import_permission(self, request: WSGIRequest):
"""Return whether a request has import permission."""
IMPORT_PERMISSION_CODE = getattr(
settings,
Expand All @@ -386,7 +386,11 @@ def has_import_permission(self, request):
codename = get_permission_codename(IMPORT_PERMISSION_CODE, opts)
return request.user.has_perm("%s.%s" % (opts.app_label, codename))

def changelist_view(self, request, context=None):
def changelist_view(
self,
request: WSGIRequest,
context: typing.Optional[dict[str, typing.Any]] = None,
):
"""Add the check for permission to changelist template context."""
context = context or {}
context["has_import_permission"] = self.has_import_permission(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.contrib import admin, messages
from django.core.handlers.wsgi import WSGIRequest
from django.db.models import QuerySet
from django.http import JsonResponse
from django.urls import re_path
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -36,9 +37,9 @@ class ExportJobAdmin(
export_job_model = models.ExportJob
list_filter = ("export_status",)
list_select_related = ("created_by",)
actions = [
actions = (
"cancel_jobs",
]
)

def export_data_action(
self,
Expand Down Expand Up @@ -215,7 +216,7 @@ def get_fieldsets(
return [status, traceback_fields, export_params]

@admin.action(description="Cancel selected jobs")
def cancel_jobs(self, request, queryset):
def cancel_jobs(self, request: WSGIRequest, queryset: QuerySet):
"""Admin action for cancelling data export."""
for job in queryset:
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.contrib import admin, messages
from django.core.handlers.wsgi import WSGIRequest
from django.db.models import QuerySet
from django.http import JsonResponse
from django.template.loader import render_to_string
from django.urls import re_path
Expand Down Expand Up @@ -38,10 +39,10 @@ class ImportJobAdmin(
import_job_model = models.ImportJob
list_filter = ("import_status",)
list_select_related = ("created_by",)
actions = [
actions = (
"cancel_jobs",
"confirm_jobs",
]
)

def get_queryset(self, request: WSGIRequest):
"""Override `get_queryset`.
Expand Down Expand Up @@ -260,7 +261,7 @@ def get_fieldsets(
return [status, traceback_, import_params]

@admin.action(description="Cancel selected jobs")
def cancel_jobs(self, request, queryset):
def cancel_jobs(self, request: WSGIRequest, queryset: QuerySet):
"""Admin action for cancelling data import."""
for job in queryset:
try:
Expand All @@ -274,7 +275,7 @@ def cancel_jobs(self, request, queryset):
self.message_user(request, str(error), messages.ERROR)

@admin.action(description="Confirm selected jobs")
def confirm_jobs(self, request, queryset):
def confirm_jobs(self, request: WSGIRequest, queryset: QuerySet):
"""Admin action for confirming data import."""
for job in queryset:
try:
Expand Down

0 comments on commit 2711f57

Please sign in to comment.