Display files urls and copy button
This commit is contained in:
parent
c86e15596b
commit
6898bb22a5
2 changed files with 33 additions and 1 deletions
|
@ -6,5 +6,20 @@ from attachments.models import Attachment
|
||||||
|
|
||||||
@register(Attachment)
|
@register(Attachment)
|
||||||
class AttachmentAdmin(admin.ModelAdmin):
|
class AttachmentAdmin(admin.ModelAdmin):
|
||||||
list_display = ["description", "original_file", "processed_file"]
|
list_display = [
|
||||||
|
"description",
|
||||||
|
"original_file",
|
||||||
|
"original_file_url",
|
||||||
|
"processed_file",
|
||||||
|
"processed_file_url",
|
||||||
|
]
|
||||||
list_display_links = ["description"]
|
list_display_links = ["description"]
|
||||||
|
|
||||||
|
class Media:
|
||||||
|
js = ["attachments/js/copy_url.js"]
|
||||||
|
|
||||||
|
def processed_file_url(self, instance):
|
||||||
|
return instance.processed_file.url
|
||||||
|
|
||||||
|
def original_file_url(self, instance):
|
||||||
|
return instance.original_file.url
|
||||||
|
|
17
attachments/static/attachments/js/copy_url.js
Normal file
17
attachments/static/attachments/js/copy_url.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
function copy(data) {
|
||||||
|
navigator.clipboard.writeText(data).then(() => {
|
||||||
|
console.log("Copied");
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
const $ = django.jQuery;
|
||||||
|
const fileUrls = $('td.field-processed_file_url, td.field-original_file_url');
|
||||||
|
for (let fileUrl of fileUrls) {
|
||||||
|
fileUrl = $(fileUrl);
|
||||||
|
const existingText = fileUrl.text();
|
||||||
|
const copyButton = `<a class='copy-button' href='#' onclick="copy(\'${existingText}\')">📋</a>`;
|
||||||
|
let innerHTML = `<span>${existingText}</span> ${copyButton}`;
|
||||||
|
fileUrl.html(innerHTML);
|
||||||
|
}
|
||||||
|
});
|
Reference in a new issue