mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-29 05:42:09 +02:00
* Initial work on #19591 * Ignore images cache directory * Clean up thumbnails layout * Include "add attachment" button * Clean up ObjectImageAttachmentsView * Add html_tag property to ImageAttachment * Misc cleanup * Collapse .gitignore files for /media * Fix conditional in template
This commit is contained in:
@@ -9,6 +9,8 @@ from django.core.validators import ValidationError
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework.utils.encoders import JSONEncoder
|
||||
|
||||
@@ -728,6 +730,18 @@ class ImageAttachment(ChangeLoggedModel):
|
||||
def filename(self):
|
||||
return os.path.basename(self.image.name).split('_', 2)[2]
|
||||
|
||||
@property
|
||||
def html_tag(self):
|
||||
"""
|
||||
Returns a complete <img> tag suitable for embedding in an HTML document.
|
||||
"""
|
||||
return mark_safe('<img src="{url}" height="{height}" width="{width}" alt="{alt_text}" />'.format(
|
||||
url=self.image.url,
|
||||
height=self.image_height,
|
||||
width=self.image_width,
|
||||
alt_text=escape(self.description or self.name),
|
||||
))
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user