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 hashlib
|
||||||
|
import logging
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from django import template
|
from django import template
|
||||||
|
|
@ -13,6 +14,9 @@ from regidesk.models import CheckIn
|
||||||
CONFERENCE_ID = settings.CONFERENCE_ID
|
CONFERENCE_ID = settings.CONFERENCE_ID
|
||||||
GST_RATE = settings.GST_RATE
|
GST_RATE = settings.GST_RATE
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
register = template.Library()
|
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. '''
|
''' Provides the speaker profile, or else fall back to libravatar or gravatar. '''
|
||||||
|
|
||||||
if speaker.photo:
|
if speaker.photo:
|
||||||
thumbnailer = get_thumbnailer(speaker.photo)
|
try:
|
||||||
thumbnail_options = {'crop': True, 'size': (size, size)}
|
thumbnailer = get_thumbnailer(speaker.photo)
|
||||||
thumbnail = thumbnailer.get_thumbnail(thumbnail_options)
|
thumbnail_options = {'crop': True, 'size': (size, size)}
|
||||||
return thumbnail.url
|
thumbnail = thumbnailer.get_thumbnail(thumbnail_options)
|
||||||
else:
|
return thumbnail.url
|
||||||
email = speaker.user.email.encode("utf-8")
|
except:
|
||||||
md5sum = hashlib.md5(email.strip().lower()).hexdigest()
|
log.exception("Cannot create thumbnail for speaker %s, image %s" % speaker.code, speaker.photo)
|
||||||
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
|
# 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()
|
@register.simple_tag()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue