|
5 | 5 | from api.helpers.ids import encode_hashid |
6 | 6 | from django.conf import settings |
7 | 7 |
|
| 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 | + |
8 | 18 |
|
9 | 19 | class ParticipantQuerySet(ConferenceQuerySetMixin, models.QuerySet): |
10 | 20 | pass |
@@ -40,6 +50,7 @@ class SpeakerLevels(models.TextChoices): |
40 | 50 | blank=True, |
41 | 51 | related_name="participants", |
42 | 52 | ) |
| 53 | + |
43 | 54 | bio = models.TextField(max_length=2048) |
44 | 55 | website = models.URLField(max_length=2048, blank=True) |
45 | 56 | twitter_handle = models.CharField(max_length=15, blank=True) |
@@ -68,6 +79,18 @@ def hashid(self): |
68 | 79 | def photo_url(self): |
69 | 80 | return self.photo_file.url if self.photo_file else self.photo |
70 | 81 |
|
| 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 | + |
71 | 94 | def __str__(self) -> str: |
72 | 95 | return f"Participant {self.user_id} for {self.conference}" |
73 | 96 |
|
|
0 commit comments