many improvements
This commit is contained in:
+14
-3
@@ -20,7 +20,7 @@ from pydicom.errors import InvalidDicomError
|
||||
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.conf import settings
|
||||
from django.utils.html import format_html
|
||||
from django.utils.html import format_html, mark_safe
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
@@ -39,6 +39,8 @@ from helpers.images import (
|
||||
pretty_print_dicom,
|
||||
)
|
||||
|
||||
import mimetypes
|
||||
|
||||
|
||||
from generic.models import (
|
||||
CidUser,
|
||||
@@ -1199,11 +1201,20 @@ class Resource(models.Model, AuthorMixin):
|
||||
if self.url:
|
||||
html = f"<a target='_blank' href='{self.url}'>{self.name}</a>"
|
||||
elif self.file:
|
||||
html = f"<a target='_blank' href='{self.file.url}'>{self.name}</a>"
|
||||
filetype, _ = mimetypes.guess_type(self.file.url)
|
||||
|
||||
match filetype.split("/"):
|
||||
case "image", _:
|
||||
html = f"<img src='{self.file.url}'>"
|
||||
case "video", _:
|
||||
html = f"<video controls><source src='{self.file.url}'></video>"
|
||||
|
||||
case _:
|
||||
html = f"<a target='_blank' href='{self.file.url}'>{self.name}</a>"
|
||||
else:
|
||||
html = self.name
|
||||
|
||||
return format_html(html)
|
||||
return format_html("<details class='resource-block'><summary>{}</summary>{}</details>", self.name, mark_safe(html))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user