mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Attachment URL method (#5584)
* Attachment fully-qualified-url Adds method to generate a fully-qualified URL for an attachment * Construct absolute URL including host information
This commit is contained in:
parent
0f8cddd23d
commit
6cde460567
@ -440,7 +440,8 @@ class InvenTreeAttachment(models.Model):
|
||||
An attachment can be either an uploaded file, or an external URL
|
||||
|
||||
Attributes:
|
||||
attachment: File
|
||||
attachment: Upload file
|
||||
link: External URL
|
||||
comment: String descriptor for the attachment
|
||||
user: User associated with file upload
|
||||
upload_date: Date the file was uploaded
|
||||
@ -564,6 +565,22 @@ class InvenTreeAttachment(models.Model):
|
||||
except Exception:
|
||||
raise ValidationError(_("Error renaming file"))
|
||||
|
||||
def fully_qualified_url(self):
|
||||
"""Return a 'fully qualified' URL for this attachment.
|
||||
|
||||
- If the attachment is a link to an external resource, return the link
|
||||
- If the attachment is an uploaded file, return the fully qualified media URL
|
||||
"""
|
||||
|
||||
if self.link:
|
||||
return self.link
|
||||
|
||||
if self.attachment:
|
||||
media_url = InvenTree.helpers.getMediaUrl(self.attachment.url)
|
||||
return InvenTree.helpers_model.construct_absolute_url(media_url)
|
||||
|
||||
return ''
|
||||
|
||||
|
||||
class InvenTreeTree(MPTTModel):
|
||||
"""Provides an abstracted self-referencing tree model for data categories.
|
||||
|
Loading…
Reference in New Issue
Block a user