Files
@ 39b556b7ac4f
Branch filter:
Location: symposion_app/pinaxcon/templatetags/lca2017_tags.py - annotation
39b556b7ac4f
2.9 KiB
text/x-python
Mass style-check update
Seems okay.
Seems okay.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 a3474fd9cd4c e6c623a69ca9 a3474fd9cd4c ff16f71df6e8 ff16f71df6e8 a3474fd9cd4c 0eda616345b9 ff16f71df6e8 a3474fd9cd4c ff16f71df6e8 e6c623a69ca9 e6c623a69ca9 ff16f71df6e8 e6c623a69ca9 e6c623a69ca9 e6c623a69ca9 ecabf31e54b9 ff16f71df6e8 ecabf31e54b9 ecabf31e54b9 ecabf31e54b9 ecabf31e54b9 ff16f71df6e8 ecabf31e54b9 ecabf31e54b9 ecabf31e54b9 ecabf31e54b9 ff16f71df6e8 ecabf31e54b9 ecabf31e54b9 ecabf31e54b9 ecabf31e54b9 ff16f71df6e8 ff16f71df6e8 8d68cca01f87 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 8d68cca01f87 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 39b556b7ac4f 39b556b7ac4f 39b556b7ac4f ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 5be0c8be19f7 5be0c8be19f7 5be0c8be19f7 5be0c8be19f7 5be0c8be19f7 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 ff16f71df6e8 a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c 0eda616345b9 39b556b7ac4f 0eda616345b9 0eda616345b9 0eda616345b9 0eda616345b9 0eda616345b9 0eda616345b9 0eda616345b9 | import cms_pages
import hashlib
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()
@register.assignment_tag()
def classname(ob):
return ob.__class__.__name__
@register.simple_tag(takes_context=True)
def can_manage(context, proposal):
return proposal_permission(context, "manage", proposal)
@register.simple_tag(takes_context=True)
def can_review(context, proposal):
return proposal_permission(context, "review", proposal)
def proposal_permission(context, permname, proposal):
slug = proposal.kind.section.slug
perm = "reviews.can_%s_%s" % (permname, slug)
return context.request.user.has_perm(perm)
# {% load statictags %}{% static 'pyconau2017/images/svgs/illustrations/' %}{{ illustration }}
@register.simple_tag(takes_context=False)
def illustration(name):
return staticfiles.static('pyconau2017/images/svgs/illustrations/') + 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()
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
@register.simple_tag()
def presentation_bg_number(presentation, count):
return sum(ord(i) for i in presentation.title) % count
@register.simple_tag()
def header_paragraph(name):
model = cms_pages.models.NamedHeaderParagraph
try:
return model.objects.get(name=name).text
except model.DoesNotExist:
return ""
@register.simple_tag()
def all_images():
return cms_pages.models.CustomImage.objects.all().order_by("title")
@register.filter()
def gst(amount):
two_places = Decimal(10) ** -2
return Decimal(amount / 11).quantize(two_places)
@register.simple_tag()
def conference_name():
return conference_models.Conference.objects.get(id=CONFERENCE_ID).title
@register.filter()
def trackname(room, day):
try:
track_name = room.track_set.get(day=day).name
except Track.DoesNotExist:
track_name = None
return track_name
|