Extend compatibility with Django 6.0

This commit is contained in:
2025-12-03 23:24:53 +01:00
parent 935c439084
commit 66c3c3f51c
5 changed files with 29 additions and 25 deletions

View File

@@ -2,7 +2,7 @@ import html
from django.conf import settings from django.conf import settings
from django.contrib import admin from django.contrib import admin
from django.utils.html import format_html, strip_tags from django.utils.html import format_html, format_html_join, strip_tags
from adminsortable2.admin import SortableAdminBase, SortableInlineAdminMixin from adminsortable2.admin import SortableAdminBase, SortableInlineAdminMixin
from ram.admin import publish, unpublish from ram.admin import publish, unpublish
@@ -123,13 +123,14 @@ class BookAdmin(SortableAdminBase, admin.ModelAdmin):
@admin.display(description="Invoices") @admin.display(description="Invoices")
def invoices(self, obj): def invoices(self, obj):
if obj.invoice.exists(): if obj.invoice.exists():
html = "<br>".join( html = format_html_join(
"<a href=\"{}\" target=\"_blank\">{}</a>".format( "<br>",
i.file.url, i "<a href=\"{}\" target=\"_blank\">{}</a>",
) for i in obj.invoice.all()) ((i.file.url, i) for i in obj.invoice.all())
)
else: else:
html = "-" html = "-"
return format_html(html) return html
@admin.display(description="Publisher") @admin.display(description="Publisher")
def get_publisher(self, obj): def get_publisher(self, obj):
@@ -207,7 +208,7 @@ class PublisherAdmin(admin.ModelAdmin):
@admin.display(description="Country") @admin.display(description="Country")
def country_flag(self, obj): def country_flag(self, obj):
return format_html( return format_html(
'<img src="{}" /> {}'.format(obj.country.flag, obj.country.name) '<img src="{}" /> {}', obj.country.flag, obj.country.name
) )
@@ -285,13 +286,14 @@ class CatalogAdmin(SortableAdminBase, admin.ModelAdmin):
@admin.display(description="Invoices") @admin.display(description="Invoices")
def invoices(self, obj): def invoices(self, obj):
if obj.invoice.exists(): if obj.invoice.exists():
html = "<br>".join( html = format_html_join(
"<a href=\"{}\" target=\"_blank\">{}</a>".format( "<br>",
i.file.url, i "<a href=\"{}\" target=\"_blank\">{}</a>",
) for i in obj.invoice.all()) ((i.file.url, i) for i in obj.invoice.all())
)
else: else:
html = "-" html = "-"
return format_html(html) return html
def download_csv(modeladmin, request, queryset): def download_csv(modeladmin, request, queryset):
header = [ header = [

View File

@@ -54,7 +54,7 @@ class ConsistAdmin(SortableAdminBase, admin.ModelAdmin):
@admin.display(description="Country") @admin.display(description="Country")
def country_flag(self, obj): def country_flag(self, obj):
return format_html( return format_html(
'<img src="{}" /> {}'.format(obj.country.flag, obj.country) '<img src="{}" /> {}', obj.country.flag, obj.country
) )
fieldsets = ( fieldsets = (

View File

@@ -54,7 +54,7 @@ class CompanyAdmin(admin.ModelAdmin):
@admin.display(description="Country") @admin.display(description="Country")
def country_flag(self, obj): def country_flag(self, obj):
return format_html( return format_html(
'<img src="{}" /> {}'.format(obj.country.flag, obj.country.name) '<img src="{}" /> {}', obj.country.flag, obj.country.name
) )
@@ -68,7 +68,7 @@ class ManufacturerAdmin(admin.ModelAdmin):
@admin.display(description="Country") @admin.display(description="Country")
def country_flag(self, obj): def country_flag(self, obj):
return format_html( return format_html(
'<img src="{}" /> {}'.format(obj.country.flag, obj.country.name) '<img src="{}" /> {}', obj.country.flag, obj.country.name
) )

View File

@@ -48,8 +48,9 @@ def git_suffix(fname):
def get_image_preview(url, max_size=150): def get_image_preview(url, max_size=150):
return format_html( return format_html(
'<img src="{src}" style="max-width: {size}px; max-height: {size}px;' '<img src="{src}" style="max-width: {size}px; max-height: {size}px; background-color: #eee;" />', # noqa: E501
'background-color: #eee;" />'.format(src=url, size=max_size) src=url,
size=max_size,
) )

View File

@@ -2,7 +2,7 @@ import html
from django.conf import settings from django.conf import settings
from django.contrib import admin from django.contrib import admin
from django.utils.html import format_html, strip_tags from django.utils.html import format_html, format_html_join, strip_tags
from adminsortable2.admin import SortableAdminBase, SortableInlineAdminMixin from adminsortable2.admin import SortableAdminBase, SortableInlineAdminMixin
@@ -44,7 +44,7 @@ class RollingClass(admin.ModelAdmin):
@admin.display(description="Country") @admin.display(description="Country")
def country_flag(self, obj): def country_flag(self, obj):
return format_html( return format_html(
'<img src="{}" /> {}'.format(obj.country.flag, obj.country) '<img src="{}" /> {}', obj.country.flag, obj.country.name
) )
@@ -152,7 +152,7 @@ class RollingStockAdmin(SortableAdminBase, admin.ModelAdmin):
@admin.display(description="Country") @admin.display(description="Country")
def country_flag(self, obj): def country_flag(self, obj):
return format_html( return format_html(
'<img src="{}" /> {}'.format(obj.country.flag, obj.country) '<img src="{}" /> {}', obj.country.flag, obj.country.name
) )
fieldsets = ( fieldsets = (
@@ -222,13 +222,14 @@ class RollingStockAdmin(SortableAdminBase, admin.ModelAdmin):
@admin.display(description="Invoices") @admin.display(description="Invoices")
def invoices(self, obj): def invoices(self, obj):
if obj.invoice.exists(): if obj.invoice.exists():
html = "<br>".join( html = format_html_join(
"<a href=\"{}\" target=\"_blank\">{}</a>".format( "<br>",
i.file.url, i "<a href=\"{}\" target=\"_blank\">{}</a>",
) for i in obj.invoice.all()) ((i.file.url, i) for i in obj.invoice.all())
)
else: else:
html = "-" html = "-"
return format_html(html) return html
def download_csv(modeladmin, request, queryset): def download_csv(modeladmin, request, queryset):
header = [ header = [