.
This commit is contained in:
@@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -29,6 +29,11 @@ import reversion
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
import pydicom
|
||||||
|
import pydicom.errors
|
||||||
|
|
||||||
image_storage = FileSystemStorage(
|
image_storage = FileSystemStorage(
|
||||||
# Physical file location ROOT
|
# Physical file location ROOT
|
||||||
location=u"{0}".format(settings.MEDIA_ROOT),
|
location=u"{0}".format(settings.MEDIA_ROOT),
|
||||||
@@ -432,6 +437,10 @@ class RapidImage(models.Model):
|
|||||||
|
|
||||||
feedback_image = models.BooleanField(default=False)
|
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):
|
def image_tag(self):
|
||||||
if self.image:
|
if self.image:
|
||||||
return mark_safe(
|
return mark_safe(
|
||||||
@@ -442,6 +451,19 @@ class RapidImage(models.Model):
|
|||||||
|
|
||||||
image_tag.short_description = 'Image'
|
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):
|
class RapidCreationDefault(models.Model):
|
||||||
#author = models.OneToOneField(User,
|
#author = models.OneToOneField(User,
|
||||||
|
|||||||
@@ -22,3 +22,4 @@ django-tinymce
|
|||||||
django-zipview
|
django-zipview
|
||||||
pymemcache
|
pymemcache
|
||||||
django-autocomplete-light
|
django-autocomplete-light
|
||||||
|
django-querysetsequence
|
||||||
Reference in New Issue
Block a user