mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
Removed changes from setting.py. Add convert handler for device model.
This commit is contained in:
parent
fbcb439384
commit
48d57d3a35
@ -1,16 +1,24 @@
|
|||||||
import decimal
|
import decimal
|
||||||
|
import sys
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.contrib.contenttypes.fields import GenericRelation
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.core.files.uploadedfile import InMemoryUploadedFile
|
||||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import F, ProtectedError
|
from django.db.models import F, ProtectedError
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
|
try:
|
||||||
|
from pillow_heif import HeifImageFile, HeifImagePlugin
|
||||||
|
except ImportError:
|
||||||
|
HeifImagePlugin = HeifImageFile = None
|
||||||
|
|
||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
from dcim.constants import *
|
from dcim.constants import *
|
||||||
from extras.models import ConfigContextModel
|
from extras.models import ConfigContextModel
|
||||||
@ -21,7 +29,6 @@ from utilities.choices import ColorChoices
|
|||||||
from utilities.fields import ColorField, NaturalOrderingField
|
from utilities.fields import ColorField, NaturalOrderingField
|
||||||
from .device_components import *
|
from .device_components import *
|
||||||
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'Device',
|
'Device',
|
||||||
'DeviceRole',
|
'DeviceRole',
|
||||||
@ -280,6 +287,16 @@ class DeviceType(NetBoxModel):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
if HeifImagePlugin is not None:
|
||||||
|
for im in (self.front_image, self.rear_image):
|
||||||
|
if im and isinstance(im.file, InMemoryUploadedFile) and isinstance(im.file.image, HeifImageFile):
|
||||||
|
output_stream = BytesIO()
|
||||||
|
im.file.image.save(output_stream, format="JPEG")
|
||||||
|
output_stream.seek(0)
|
||||||
|
im.name = "%s.jpg" % im.file.name.split('.')[0]
|
||||||
|
im.file = InMemoryUploadedFile(output_stream, 'ImageField', im.name,
|
||||||
|
'image/jpeg', sys.getsizeof(output_stream), None)
|
||||||
|
|
||||||
ret = super().save(*args, **kwargs)
|
ret = super().save(*args, **kwargs)
|
||||||
|
|
||||||
# Delete any previously uploaded image files that are no longer in use
|
# Delete any previously uploaded image files that are no longer in use
|
||||||
|
@ -24,11 +24,6 @@ import django
|
|||||||
from django.utils.encoding import force_str
|
from django.utils.encoding import force_str
|
||||||
django.utils.encoding.force_text = force_str
|
django.utils.encoding.force_text = force_str
|
||||||
|
|
||||||
try:
|
|
||||||
from pillow_heif import HeifImagePlugin
|
|
||||||
except ImportError:
|
|
||||||
HeifImagePlugin = None
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Environment setup
|
# Environment setup
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user