Handle exceptions for speaker thumbnails

Log exceptions when generating speaker thumbnails
to avoid the entire page not loading.
This commit is contained in:
Joel Addison 2024-03-16 18:01:41 +10:00
parent d7c45c535e
commit fd5883014c

View file

@ -1,4 +1,5 @@
import hashlib
import logging
from decimal import Decimal
from django import template
@ -13,6 +14,9 @@ from regidesk.models import CheckIn
CONFERENCE_ID = settings.CONFERENCE_ID
GST_RATE = settings.GST_RATE
log = logging.getLogger(__name__)
register = template.Library()
@ -42,17 +46,18 @@ def speaker_photo(context, speaker, size):
''' Provides the speaker profile, or else fall back to libravatar or gravatar. '''
if speaker.photo:
try:
thumbnailer = get_thumbnailer(speaker.photo)
thumbnail_options = {'crop': True, 'size': (size, size)}
thumbnail = thumbnailer.get_thumbnail(thumbnail_options)
return thumbnail.url
else:
except:
log.exception("Cannot create thumbnail for speaker %s, image %s" % speaker.code, speaker.photo)
# Use gravatar if no photo can be used.
email = speaker.user.email.encode("utf-8")
md5sum = hashlib.md5(email.strip().lower()).hexdigest()
fallback_image = ("https://linux.conf.au/site_media/static/lca2017"
"/images/speaker-fallback-devil.jpg")
url = "https://secure.gravatar.com/avatar/%s?s=%d&d=%s" % (md5sum, size, "mp")
return url