Display files urls and copy button

This commit is contained in:
Gabriel Augendre 2020-08-28 21:49:15 +02:00
parent c86e15596b
commit 6898bb22a5
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
2 changed files with 33 additions and 1 deletions

View file

@ -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

View 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}\')">&#128203;</a>`;
let innerHTML = `<span>${existingText}</span> ${copyButton}`;
fileUrl.html(innerHTML);
}
});