add simple case and series size display

This commit is contained in:
Ross
2024-12-19 00:02:26 +00:00
parent e0974ae300
commit 8c43c40215
6 changed files with 83 additions and 1 deletions
@@ -0,0 +1,18 @@
# Generated by Django 5.0.2 on 2024-12-18 23:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('atlas', '0064_casecollection_exam_open_access'),
]
operations = [
migrations.AddField(
model_name='series',
name='total_image_size',
field=models.BigIntegerField(blank=True, help_text='Stores a (cached) total size of images within the series', null=True),
),
]
@@ -0,0 +1,18 @@
# Generated by Django 5.0.2 on 2024-12-18 23:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('atlas', '0065_series_total_image_size'),
]
operations = [
migrations.AddField(
model_name='case',
name='total_images_series_size',
field=models.BigIntegerField(blank=True, null=True),
),
]
+13
View File
@@ -390,6 +390,8 @@ class Case(models.Model, AuthorMixin, QuestionMixin):
resource = models.ManyToManyField("Resource", through="CaseResource")
total_images_series_size = models.BigIntegerField(null=True, blank=True)
def get_app_name(self):
return "atlas"
@@ -495,6 +497,17 @@ class Case(models.Model, AuthorMixin, QuestionMixin):
def get_series(self):
return self.series.all().prefetch_related("images", "examination", "plane")
def get_total_series_images_size(self, refresh=False):
if self.total_images_series_size is not None and not refresh:
return self.total_images_series_size
series = self.series.all()
size = sum(s.get_total_image_size(refresh=refresh) for s in series)
return size
def extract_image_dicom_json_from_ds(ds, url, image_index):
to_keep = [
@@ -188,3 +188,6 @@
<p><b>Author(s):</b> {% for author in case.author.all %} <a
href="{% url 'atlas:author_detail' pk=author.pk %}">{{author}}</a>, {% endfor %}</p>
<p><b>Case size:</b> {{ case.get_total_series_images_size | filesizeformat }}</p>
+13 -1
View File
@@ -336,6 +336,8 @@ class SeriesBase(models.Model):
choices=SeriesModifiedChocies.choices,
)
total_image_size = models.BigIntegerField(null=True, blank=True, help_text="Stores a (cached) total size of images within the series")
class Meta:
abstract = True
@@ -531,7 +533,14 @@ class SeriesBase(models.Model):
i.save()
n = n + 1
def get_total_image_size(self):
def get_total_image_size(self, refresh=False):
"""Returns the total size of all images in the series.
If refresh is set to True the size will be recalculated and saved to the database
(in the field 'total_image_size')."""
if not refresh and self.total_image_size:
return self.total_image_size
images = self.images.filter(removed=False)
size = 0
@@ -539,6 +548,9 @@ class SeriesBase(models.Model):
for i in images:
size += i.get_file_size()
self.total_image_size = size
self.save()
return size
def anonymise_images(self):
@@ -0,0 +1,18 @@
# Generated by Django 5.0.2 on 2024-12-18 23:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('longs', '0031_exam_results_supervisor_visible'),
]
operations = [
migrations.AddField(
model_name='longseries',
name='total_image_size',
field=models.BigIntegerField(blank=True, help_text='Stores a (cached) total size of images within the series', null=True),
),
]