import cms_pages
import hashlib
import urllib
from decimal import Decimal
from django import template
from django.conf import settings
from django.contrib.staticfiles.templatetags import staticfiles
from easy_thumbnails.files import get_thumbnailer
from symposion.conference import models as conference_models
from symposion.schedule.models import Track
CONFERENCE_ID = settings.CONFERENCE_ID
register = template.Library()
@@ -46,25 +45,27 @@ def illustration(name):
@register.simple_tag(takes_context=True)
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()
url = "https://secure.gravatar.com/avatar/%s?s=%d&d=%s" % (md5sum, size, "https://linux.conf.au/site_media/static/lca2017/images/speaker-fallback-devil.jpg")
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, fallback_image)
return url
@register.simple_tag()
def define(value):
return value
def presentation_bg_number(presentation, count):
return sum(ord(i) for i in presentation.title) % count
@@ -85,19 +86,20 @@ def all_images():
@register.filter()
def gst(amount):
two_places = Decimal(10) ** -2
return Decimal(amount / 11).quantize(two_places)
def conference_name():
return conference_models.Conference.objects.get(id=CONFERENCE_ID).title
def trackname(room, day):
try:
track_name = room.track_set.get(day=day).name
except Track.DoesNotExist:
track_name = None
return track_name