Skip to content

Commit 6c365ca

Browse files
authored
Add photo_small to participants (#4413)
1 parent a85dd90 commit 6c365ca

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

backend/api/participants/types.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class Participant:
1616
id: ID
1717
bio: str
1818
website: str
19-
photo: str | None
19+
_photo: strawberry.Private[str]
20+
_photo_small: strawberry.Private[str]
2021
photo_id: str | None
2122
public_profile: bool
2223
twitter_handle: str
@@ -62,12 +63,20 @@ def previous_talk_video(self, info) -> str | None:
6263

6364
return self._previous_talk_video
6465

66+
@strawberry.field
67+
def photo(self, size: str = "default") -> str | None:
68+
if size == "small":
69+
return self._photo_small
70+
71+
return self._photo
72+
6573
@classmethod
6674
def from_model(cls, instance):
6775
return cls(
6876
id=instance.hashid,
6977
fullname=instance.user.fullname,
70-
photo=instance.photo_url,
78+
_photo=instance.photo_url,
79+
_photo_small=instance.photo_small_url,
7180
photo_id=instance.photo_file_id,
7281
bio=instance.bio,
7382
website=instance.website,

backend/participants/models.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
from api.helpers.ids import encode_hashid
66
from django.conf import settings
77

8+
from imagekit import ImageSpec
9+
from imagekit.processors import ResizeToFill
10+
from imagekit.cachefiles import ImageCacheFile
11+
12+
13+
class ParticipantThumbnail(ImageSpec):
14+
processors = [ResizeToFill(200, 200)]
15+
format = "JPEG"
16+
options = {"quality": 60}
17+
818

919
class ParticipantQuerySet(ConferenceQuerySetMixin, models.QuerySet):
1020
pass
@@ -40,6 +50,7 @@ class SpeakerLevels(models.TextChoices):
4050
blank=True,
4151
related_name="participants",
4252
)
53+
4354
bio = models.TextField(max_length=2048)
4455
website = models.URLField(max_length=2048, blank=True)
4556
twitter_handle = models.CharField(max_length=15, blank=True)
@@ -68,6 +79,18 @@ def hashid(self):
6879
def photo_url(self):
6980
return self.photo_file.url if self.photo_file else self.photo
7081

82+
@property
83+
def photo_small_url(self):
84+
if not self.photo_file:
85+
return None
86+
87+
image_generator = ImageCacheFile(
88+
ParticipantThumbnail(source=self.photo_file.file)
89+
)
90+
image_generator.generate()
91+
92+
return image_generator.url
93+
7194
def __str__(self) -> str:
7295
return f"Participant {self.user_id} for {self.conference}"
7396

0 commit comments

Comments
 (0)