from django import template from losttheories lost_episodes models imp

 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
from django import template
from losttheories.lost_episodes.models import Episode
register = template.Library()
class EpisodeListNode(template.Node):
def __init__(self,varname):
self.varname = varname
def __repr__(self):
return "<EpisodeList Node>"
def render(self, context):
context[self.varname] = Episode.objects.all()
return ''
class DoGetEpisodeList:
"""
{% get_episode_list as episode_list %}
"""
def __init__(self, tag_name):
self.tag_name = tag_name
def __call__(self, parser, token):
bits = token.contents.split()
if len(bits) != 3:
raise template.TemplateSyntaxError, "'%s' tag takes two arguments" % bits[0]
if bits[1] != "as":
raise template.TemplateSyntaxError, "First argument to '%s' tag must be 'as'" % bits[0]
return EpisodeListNode(bits[2])
register.tag('get_episode_list', DoGetEpisodeList('get_episode_list'))