Handle exceptions for speaker thumbnails
Log exceptions when generating speaker thumbnails to avoid the entire page not loading.
This commit is contained in:
parent
d7c45c535e
commit
fd5883014c
1 changed files with 16 additions and 11 deletions
|
|
@ -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,18 +46,19 @@ def speaker_photo(context, speaker, size):
|
|||
''' Provides the speaker profile, or else fall back to libravatar or gravatar. '''
|
||||
|
||||
if speaker.photo:
|
||||
thumbnailer = get_thumbnailer(speaker.photo)
|
||||
thumbnail_options = {'crop': True, 'size': (size, size)}
|
||||
thumbnail = thumbnailer.get_thumbnail(thumbnail_options)
|
||||
return thumbnail.url
|
||||
else:
|
||||
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")
|
||||
try:
|
||||
thumbnailer = get_thumbnailer(speaker.photo)
|
||||
thumbnail_options = {'crop': True, 'size': (size, size)}
|
||||
thumbnail = thumbnailer.get_thumbnail(thumbnail_options)
|
||||
return thumbnail.url
|
||||
except:
|
||||
log.exception("Cannot create thumbnail for speaker %s, image %s" % speaker.code, speaker.photo)
|
||||
|
||||
return url
|
||||
# Use gravatar if no photo can be used.
|
||||
email = speaker.user.email.encode("utf-8")
|
||||
md5sum = hashlib.md5(email.strip().lower()).hexdigest()
|
||||
url = "https://secure.gravatar.com/avatar/%s?s=%d&d=%s" % (md5sum, size, "mp")
|
||||
return url
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue