.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user