From 944be50dbf6347659cbf108a19ce0dbf21193b43 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 15 Nov 2020 23:01:55 +0000 Subject: [PATCH] Add checks to card photo generation --- apiserver/apiserver/api/utils.py | 8 ++++---- apiserver/apiserver/api/views.py | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apiserver/apiserver/api/utils.py b/apiserver/apiserver/api/utils.py index 37dec74..1b23cf2 100644 --- a/apiserver/apiserver/api/utils.py +++ b/apiserver/apiserver/api/utils.py @@ -229,21 +229,21 @@ def gen_card_photo(member): # check font size font_sizes = (60, 72) font = ImageFont.truetype('DejaVuSans-Bold.ttf', font_sizes[1]) - size = draw.textsize(member.last_name, font=font) + size = draw.textsize(str(member.last_name), font=font) if size[0] > CARD_TEXT_SIZE_LIMIT: font_sizes = (36, 48) font = ImageFont.truetype('DejaVuSans.ttf', font_sizes[0]) x = CARD_PHOTO_MARGIN_SIDE y = my + CARD_PHOTO_MARGIN_TOP + CARD_PHOTO_MARGIN_SIDE - draw.text((x, y), member.first_name, (0,0,0), font=font) + draw.text((x, y), str(member.first_name), (0,0,0), font=font) font = ImageFont.truetype('DejaVuSans-Bold.ttf', font_sizes[1]) y = my + CARD_PHOTO_MARGIN_TOP + CARD_PHOTO_MARGIN_SIDE + font_sizes[1] - draw.text((x, y), member.last_name, (0,0,0), font=font) + draw.text((x, y), str(member.last_name), (0,0,0), font=font) font = ImageFont.truetype('DejaVuSans.ttf', 36) - draw.text((x, 800), 'Joined: ' + str(member.application_date), (0,0,0), font=font) + draw.text((x, 800), 'Joined: ' + str(member.application_date or 'Unknown'), (0,0,0), font=font) y = CARD_PHOTO_MARGIN_SIDE draw.text((475, y), str(member.id), (0,0,0), font=font) diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py index 0625279..e4e1282 100644 --- a/apiserver/apiserver/api/views.py +++ b/apiserver/apiserver/api/views.py @@ -152,6 +152,8 @@ class MemberViewSet(Base, Retrieve, Update): if not is_admin_director(self.request.user): raise exceptions.PermissionDenied() member = self.get_object() + if not member.photo_large: + raise Http404 card_photo = utils.gen_card_photo(member) return FileResponse(card_photo, filename='card.jpg')