Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions backend/api/participants/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions backend/participants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}"

Expand Down
Loading