diff --git a/backend/api/participants/types.py b/backend/api/participants/types.py index 2d2b240483..2c55909dd5 100644 --- a/backend/api/participants/types.py +++ b/backend/api/participants/types.py @@ -16,7 +16,8 @@ class Participant: id: ID bio: str website: str - photo: str | None + _photo: strawberry.Private[str] + _photo_small: strawberry.Private[str] photo_id: str | None public_profile: bool twitter_handle: str @@ -62,12 +63,20 @@ def previous_talk_video(self, info) -> str | None: return self._previous_talk_video + @strawberry.field + def photo(self, size: str = "default") -> str | None: + if size == "small": + return self._photo_small + + return self._photo + @classmethod def from_model(cls, instance): return cls( id=instance.hashid, fullname=instance.user.fullname, - photo=instance.photo_url, + _photo=instance.photo_url, + _photo_small=instance.photo_small_url, photo_id=instance.photo_file_id, bio=instance.bio, website=instance.website, diff --git a/backend/participants/models.py b/backend/participants/models.py index 29e6cc0cb3..323378226d 100644 --- a/backend/participants/models.py +++ b/backend/participants/models.py @@ -5,6 +5,16 @@ from api.helpers.ids import encode_hashid from django.conf import settings +from imagekit import ImageSpec +from imagekit.processors import ResizeToFill +from imagekit.cachefiles import ImageCacheFile + + +class ParticipantThumbnail(ImageSpec): + processors = [ResizeToFill(200, 200)] + format = "JPEG" + options = {"quality": 60} + class ParticipantQuerySet(ConferenceQuerySetMixin, models.QuerySet): pass @@ -40,6 +50,7 @@ class SpeakerLevels(models.TextChoices): blank=True, related_name="participants", ) + bio = models.TextField(max_length=2048) website = models.URLField(max_length=2048, blank=True) twitter_handle = models.CharField(max_length=15, blank=True) @@ -68,6 +79,18 @@ def hashid(self): def photo_url(self): return self.photo_file.url if self.photo_file else self.photo + @property + def photo_small_url(self): + if not self.photo_file: + return None + + image_generator = ImageCacheFile( + ParticipantThumbnail(source=self.photo_file.file) + ) + image_generator.generate() + + return image_generator.url + def __str__(self) -> str: return f"Participant {self.user_id} for {self.conference}"