mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-18 01:32:17 -06:00
Compare commits
1 Commits
main
...
21039-avif
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae1203c07b |
@@ -4,6 +4,17 @@ from extras.choices import LogLevelChoices
|
|||||||
# Custom fields
|
# Custom fields
|
||||||
CUSTOMFIELD_EMPTY_VALUES = (None, '', [])
|
CUSTOMFIELD_EMPTY_VALUES = (None, '', [])
|
||||||
|
|
||||||
|
# ImageAttachment
|
||||||
|
IMAGE_ATTACHMENT_IMAGE_FORMATS = {
|
||||||
|
'avif': 'image/avif',
|
||||||
|
'bmp': 'image/bmp',
|
||||||
|
'gif': 'image/gif',
|
||||||
|
'jpeg': 'image/jpeg',
|
||||||
|
'jpg': 'image/jpeg',
|
||||||
|
'png': 'image/png',
|
||||||
|
'webp': 'image/webp',
|
||||||
|
}
|
||||||
|
|
||||||
# Template Export
|
# Template Export
|
||||||
DEFAULT_MIME_TYPE = 'text/plain; charset=utf-8'
|
DEFAULT_MIME_TYPE = 'text/plain; charset=utf-8'
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from core.forms.mixins import SyncedDataMixin
|
from core.forms.mixins import SyncedDataMixin
|
||||||
from core.models import ObjectType
|
from core.models import ObjectType
|
||||||
from dcim.models import DeviceRole, DeviceType, Location, Platform, Region, Site, SiteGroup
|
from dcim.models import DeviceRole, DeviceType, Location, Platform, Region, Site, SiteGroup
|
||||||
|
from extras.constants import IMAGE_ATTACHMENT_IMAGE_FORMATS
|
||||||
from extras.choices import *
|
from extras.choices import *
|
||||||
from extras.models import *
|
from extras.models import *
|
||||||
from netbox.events import get_event_type_choices
|
from netbox.events import get_event_type_choices
|
||||||
@@ -784,8 +785,11 @@ class ImageAttachmentForm(forms.ModelForm):
|
|||||||
fields = [
|
fields = [
|
||||||
'image', 'name', 'description',
|
'image', 'name', 'description',
|
||||||
]
|
]
|
||||||
help_texts = {
|
# Explicitly set 'image/avif' to support AVIF selection in Firefox
|
||||||
'name': _("If no name is specified, the file name will be used.")
|
widgets = {
|
||||||
|
'image': forms.ClearableFileInput(
|
||||||
|
attrs={'accept': ','.join(sorted(set(IMAGE_ATTACHMENT_IMAGE_FORMATS.values())))}
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from taggit.managers import _TaggableManager
|
|||||||
|
|
||||||
from netbox.context import current_request
|
from netbox.context import current_request
|
||||||
|
|
||||||
|
from .constants import IMAGE_ATTACHMENT_IMAGE_FORMATS
|
||||||
from .validators import CustomValidator
|
from .validators import CustomValidator
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@@ -78,7 +79,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 = IMAGE_ATTACHMENT_IMAGE_FORMATS.keys()
|
||||||
|
|
||||||
# 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