Add checks to card photo generation
This commit is contained in:
parent
a083a7814f
commit
944be50dbf
|
@ -229,21 +229,21 @@ def gen_card_photo(member):
|
||||||
# check font size
|
# check font size
|
||||||
font_sizes = (60, 72)
|
font_sizes = (60, 72)
|
||||||
font = ImageFont.truetype('DejaVuSans-Bold.ttf', font_sizes[1])
|
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:
|
if size[0] > CARD_TEXT_SIZE_LIMIT:
|
||||||
font_sizes = (36, 48)
|
font_sizes = (36, 48)
|
||||||
|
|
||||||
font = ImageFont.truetype('DejaVuSans.ttf', font_sizes[0])
|
font = ImageFont.truetype('DejaVuSans.ttf', font_sizes[0])
|
||||||
x = CARD_PHOTO_MARGIN_SIDE
|
x = CARD_PHOTO_MARGIN_SIDE
|
||||||
y = my + CARD_PHOTO_MARGIN_TOP + 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])
|
font = ImageFont.truetype('DejaVuSans-Bold.ttf', font_sizes[1])
|
||||||
y = my + CARD_PHOTO_MARGIN_TOP + CARD_PHOTO_MARGIN_SIDE + 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)
|
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
|
y = CARD_PHOTO_MARGIN_SIDE
|
||||||
draw.text((475, y), str(member.id), (0,0,0), font=font)
|
draw.text((475, y), str(member.id), (0,0,0), font=font)
|
||||||
|
|
||||||
|
|
|
@ -152,6 +152,8 @@ class MemberViewSet(Base, Retrieve, Update):
|
||||||
if not is_admin_director(self.request.user):
|
if not is_admin_director(self.request.user):
|
||||||
raise exceptions.PermissionDenied()
|
raise exceptions.PermissionDenied()
|
||||||
member = self.get_object()
|
member = self.get_object()
|
||||||
|
if not member.photo_large:
|
||||||
|
raise Http404
|
||||||
card_photo = utils.gen_card_photo(member)
|
card_photo = utils.gen_card_photo(member)
|
||||||
return FileResponse(card_photo, filename='card.jpg')
|
return FileResponse(card_photo, filename='card.jpg')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user