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
@@ -0,0 +1,23 @@
# Generated by Django 3.2.4 on 2021-11-21 10:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rapids', '0036_alter_exam_open_access'),
]
operations = [
migrations.AddField(
model_name='rapidimage',
name='image_md5_hash',
field=models.CharField(max_length=32, null=True),
),
migrations.AddField(
model_name='rapidimage',
name='is_dicom',
field=models.BooleanField(default=False),
),
]
+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,
+1
View File
@@ -22,3 +22,4 @@ django-tinymce
django-zipview
pymemcache
django-autocomplete-light
django-querysetsequence