Created
January 17, 2013 15:39
-
-
Save starsinmypockets/4556831 to your computer and use it in GitHub Desktop.
Load text snips
This file contains 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.conf import settings | |
from main.models import Verbiage | |
import logging | |
register = template.Library() | |
## @@TODO - add clean method: trim leading/trailing ' or " or whitespace | |
## @@TODO - exception for bad query | |
def getverb(parser, token): | |
tag, string = token.split_contents() | |
args = string.split('/') | |
logger.debug(args) | |
try: | |
verb = Verbiage.objects.get(page = args[0], name = args[1]).content | |
except: | |
return VerbNode('') | |
if verb == '': | |
return VerbNode('') | |
logger.debug(verb) | |
if verb: | |
return VerbNode(verb) | |
return '' | |
class VerbNode(template.Node): | |
def __init__(self, format_string): | |
self.format_string = format_string | |
def render(self, context): | |
return self.format_string | |
getverb = register.tag(getverb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment