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'))