mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 17:08:41 -06:00
Fixes #1114: Suppress OSError when attempting to access a delete image attachment
This commit is contained in:
parent
010f6c7f1a
commit
de58d0ecca
@ -422,6 +422,16 @@ class ImageAttachment(models.Model):
|
|||||||
# before the request finishes. (For example, to display a message indicating the ImageAttachment was deleted.)
|
# before the request finishes. (For example, to display a message indicating the ImageAttachment was deleted.)
|
||||||
self.image.name = _name
|
self.image.name = _name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def size(self):
|
||||||
|
"""
|
||||||
|
Wrapper around `image.size` to suppress an OSError in case the file is inaccessible.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return self.image.size
|
||||||
|
except OSError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# User actions
|
# User actions
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for attachment in images %}
|
{% for attachment in images %}
|
||||||
<tr>
|
<tr{% if not attachment.size %} class="danger"{% endif %}>
|
||||||
<td>
|
<td>
|
||||||
<i class="fa fa-image"></i>
|
<i class="fa fa-image"></i>
|
||||||
<a href="{{ attachment.image.url }}" target="_blank">{{ attachment }}</a>
|
<a href="{{ attachment.image.url }}" target="_blank">{{ attachment }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ attachment.image.size|filesizeformat }}</td>
|
<td>{{ attachment.size|filesizeformat }}</td>
|
||||||
<td>{{ attachment.created }}</td>
|
<td>{{ attachment.created }}</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
{% if perms.extras.change_imageattachment %}
|
{% if perms.extras.change_imageattachment %}
|
||||||
|
Loading…
Reference in New Issue
Block a user