Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna committed Jun 21, 2024
1 parent 5d82ec8 commit b52745d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion isic/core/templates/core/image_detail/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{% if PLACEHOLDER_IMAGES %}
<img src="https://picsum.photos/seed/{{image.accession.id}}/256" style="object-fit: cover;" />
{% else %}
<img src="{{ image.accession.thumbnail_256.url }}" style="object-fit: cover;" />
<img src="{{ image.accession.blob.url }}" style="object-fit: cover;" />
{% endif %}
</a>
</div>
Expand Down
6 changes: 4 additions & 2 deletions isic/ingest/models/accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ class Accession(CreationSortedTimeStampedModel, AccessionMetadata):
choices=AccessionStatus.choices, max_length=20, default=AccessionStatus.CREATING
)

# is_grayscale = models.BooleanField(null=True, blank=True)

thumbnail_256 = S3FileField(blank=True)
thumbnail_256_size = models.PositiveIntegerField(
null=True, blank=True, default=None, editable=False
Expand Down Expand Up @@ -488,9 +490,9 @@ def is_color(img: PIL.Image.Image) -> bool:
self.status = AccessionStatus.SUCCEEDED
self.save(update_fields=["status"])

# TODO
# TODO: how to do thumbnails for mosaics
def generate_thumbnail(self) -> None:
with Accession.objects.order_by("created").first().blob.open() as blob_stream:
with Path("/home/dan/p/isic/ISIC_0000001.jpg").open("rb") as blob_stream:
img: PIL.Image.Image = PIL.Image.open(blob_stream)
# Load the image so the stream can be closed
img.load()
Expand Down
45 changes: 44 additions & 1 deletion isic/ingest/tests/test_accession.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pathlib

from django.core.exceptions import ValidationError
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.urls.base import reverse
import pytest

from isic.ingest.models.accession import Accession
from isic.ingest.models.unstructured_metadata import UnstructuredMetadata
from isic.ingest.services.accession import bulk_accession_relicense
from isic.ingest.services.accession import accession_create, bulk_accession_relicense
from isic.ingest.utils.zip import Blob

data_dir = pathlib.Path(__file__).parent / "data"
Expand Down Expand Up @@ -34,6 +35,48 @@ def cc_by_accession_qs(accession_factory):
return Accession.objects.filter(id=accession.id)


@pytest.mark.django_db()
@pytest.mark.usefixtures("_eager_celery")
@pytest.mark.parametrize(
("blob_path", "blob_name"),
[
# small color
(pathlib.Path(data_dir / "ISIC_0000000.jpg"), "ISIC_0000000.jpg"),
# small grayscale
(pathlib.Path("/home/dan/p/isic/rcmtile.png"), "rcmtile.png"),
# big color
# big grayscale
(pathlib.Path("/home/dan/p/isic/vivablock.png"), "vivablock.png"),
],
ids=["small color", "small grayscale", "big grayscale"],
)
def test_accession_create_image_types(blob_path, blob_name, user, cohort, settings):
settings.CELERY_TASK_ALWAYS_EAGER = True
settings.CELERY_TASK_EAGER_PROPAGATES = True
import exifread

# with blob_path.open("rb") as f:
# tags = exifread.process_file(f)
# assert tags

f = InMemoryUploadedFile(
blob_path.open("rb"), None, blob_name, None, blob_path.stat().st_size, None
)

accession = accession_create(
creator=user,
cohort=cohort,
original_blob=f,
original_blob_name=blob_name,
original_blob_size=blob_path.stat().st_size,
)
accession.refresh_from_db()

with accession.blob.open("rb") as f:
tags = exifread.process_file(f)
assert not tags


@pytest.mark.django_db()
def test_accession_generate_thumbnail(accession_factory):
accession = accession_factory(thumbnail_256=None, thumbnail_256_size=None)
Expand Down
2 changes: 1 addition & 1 deletion isic/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def mutate_configuration(configuration: ComposedConfiguration):

# This doesn't need to be in mutate_configuration, but the locality of the storage
# configuration makes it a good place to put it.
configuration.ISIC_PLACEHOLDER_IMAGES = True
configuration.ISIC_PLACEHOLDER_IMAGES = False
# Use the MinioS3ProxyStorage for local development with ISIC_PLACEHOLDER_IMAGES
# set to False to view real images in development.
# configuration.STORAGES["default"]["BACKEND"] = (
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"django-storages>1.14.2",
"django-widget-tweaks",
"google-analytics-data",
"exifread",
"hashids",
"isic-metadata>=2.0.0",
"jaro-winkler",
Expand Down

0 comments on commit b52745d

Please sign in to comment.