This commit is contained in:
Ross
2021-11-21 10:21:03 +00:00
parent a04c8a7c6c
commit e367184cf6
3 changed files with 46 additions and 0 deletions
+22
View File
@@ -29,6 +29,11 @@ import reversion
import json
import hashlib
import pydicom
import pydicom.errors
image_storage = FileSystemStorage(
# Physical file location ROOT
location=u"{0}".format(settings.MEDIA_ROOT),
@@ -432,6 +437,10 @@ class RapidImage(models.Model):
feedback_image = models.BooleanField(default=False)
image_md5_hash = models.CharField(max_length=32, null=True)
is_dicom = models.BooleanField(default=False)
def image_tag(self):
if self.image:
return mark_safe(
@@ -442,6 +451,19 @@ class RapidImage(models.Model):
image_tag.short_description = 'Image'
def save(self, *args, **kwargs):
"""Override save method to add image hash"""
if self.image:
# Try and read the file as a dicom
try:
hash = ",".join(pydicom.dcmread(self.image).pixel_array.tostring())
self.is_dicom = True
except pydicom.errors.InvalidImageFormatError:
hash = hashlib.md5(self.image).hexdigest()
self.image_md5_hash = hash
super().save(*args, **kwargs) # Call the "real" save() method.
class RapidCreationDefault(models.Model):
#author = models.OneToOneField(User,