mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-16 16:52:17 -06:00
feat(extras): Add AVIF support for image attachments
Extends allowed image file formats to include AVIF for better modern format support. Updates form widgets to explicitly support AVIF in Firefox with the `accept` attribute. Fixes #21039
This commit is contained in:
@@ -22,7 +22,7 @@ from utilities.forms.fields import (
|
|||||||
DynamicModelMultipleChoiceField, JSONField, SlugField,
|
DynamicModelMultipleChoiceField, JSONField, SlugField,
|
||||||
)
|
)
|
||||||
from utilities.forms.rendering import FieldSet, ObjectAttribute
|
from utilities.forms.rendering import FieldSet, ObjectAttribute
|
||||||
from utilities.forms.widgets import ChoicesWidget, HTMXSelect
|
from utilities.forms.widgets import ChoicesWidget, ClearableFileInput, HTMXSelect
|
||||||
from utilities.tables import get_table_for_model
|
from utilities.tables import get_table_for_model
|
||||||
from virtualization.models import Cluster, ClusterGroup, ClusterType
|
from virtualization.models import Cluster, ClusterGroup, ClusterType
|
||||||
|
|
||||||
@@ -784,6 +784,10 @@ class ImageAttachmentForm(forms.ModelForm):
|
|||||||
fields = [
|
fields = [
|
||||||
'image', 'name', 'description',
|
'image', 'name', 'description',
|
||||||
]
|
]
|
||||||
|
# Explicitly set 'image/avif' to support AVIF selection in Firefox
|
||||||
|
widgets = {
|
||||||
|
'image': ClearableFileInput(attrs={'accept': 'image/*,image/avif'}),
|
||||||
|
}
|
||||||
help_texts = {
|
help_texts = {
|
||||||
'name': _("If no name is specified, the file name will be used.")
|
'name': _("If no name is specified, the file name will be used.")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ def image_upload(instance, filename):
|
|||||||
"""
|
"""
|
||||||
upload_dir = 'image-attachments'
|
upload_dir = 'image-attachments'
|
||||||
default_filename = 'unnamed'
|
default_filename = 'unnamed'
|
||||||
allowed_img_extensions = ('bmp', 'gif', 'jpeg', 'jpg', 'png', 'webp')
|
allowed_img_extensions = ('avif', 'bmp', 'gif', 'jpeg', 'jpg', 'png', 'webp')
|
||||||
|
|
||||||
# Normalize Windows paths and create a Path object.
|
# Normalize Windows paths and create a Path object.
|
||||||
normalized_filename = str(filename).replace('\\', '/')
|
normalized_filename = str(filename).replace('\\', '/')
|
||||||
|
|||||||
Reference in New Issue
Block a user