Created
June 12, 2013 22:14
-
-
Save grobertson/5769604 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
from django.template.base import TemplateSyntaxError | |
from django.template.loader import render_to_string | |
register = template.Library() | |
class SatisfactionNode(template.Node): | |
def __init__(self, from_object, option): | |
self.from_object = template.Variable(from_object) | |
self.option = template.Variable(option) | |
def render(self, context): | |
#return the html needed by the satisfaction dialogs | |
#TODO: templateize | |
obj = self.from_object.resolve(context) | |
rendered = render_to_string('form.html', self.option) | |
return rendered | |
@register.tag | |
def satisfaction(parser, token): | |
tokens = token.split_contents() | |
if len(tokens) is 3: | |
_, from_object, option = tokens | |
return SatisfactionNode(from_object, option) | |
message = "Too %s parameters for tag satisfaction. Expected 3." % ("many" if len(tokens) > 3 else "few") | |
raise TemplateSyntaxError(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment