remove unnecessary imports
[mygpo.git] / mygpo / web / templatetags / podcasts.py
blob3c1c65d8783ac2b835682ba8a8328f390a8852d4
1 from django import template
2 from django.utils.safestring import mark_safe
3 from django.utils.translation import ugettext as _
4 import hashlib
6 from mygpo.constants import PODCAST_LOGO_SIZE, PODCAST_LOGO_BIG_SIZE
8 register = template.Library()
10 def create_podcast_logo(podcast, size):
11 size = int(size)
12 if podcast.logo_url:
13 sha = hashlib.sha1(podcast.logo_url).hexdigest()
14 s = '<img src="/logo/%d/%s.jpg" alt="%s" height="%d" width="%d" />' % (size, sha, _('Logo'), size, size)
15 else:
16 s = '<img src="/media/podcast-%d.png" alt="%s" height="%d" width="%d" />' % (hash(podcast.title)%5, _('No Logo available'), size, size)
18 return mark_safe(s)
20 @register.filter
21 def podcast_logo(podcast):
22 return create_podcast_logo(podcast, PODCAST_LOGO_SIZE)
24 @register.filter
25 def podcast_logo_big(podcast):
26 return create_podcast_logo(podcast, PODCAST_LOGO_BIG_SIZE)
28 @register.filter
29 def podcast_status_icon(action):
30 if action.action == 1:
31 s = '<img src="/media/subscribe.png" />'
32 else:
33 s = '<img src="/media/unsubscribe.png" />'
35 return mark_safe(s)