Remove unused settings template tag
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from django.template import Library, Node, TemplateSyntaxError
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
class SettingsNode(Node):
|
||||
def __init__(self, format_string, var_name):
|
||||
self.format_string = format_string
|
||||
self.var_name = var_name
|
||||
|
||||
def render(self, context):
|
||||
context[self.var_name] = getattr(settings, self.format_string, '')
|
||||
return ''
|
||||
|
||||
|
||||
@register.tag
|
||||
def get_setting(parser, token):
|
||||
# This version uses a regular expression to parse tag contents.
|
||||
try:
|
||||
# Splitting by None == splitting by spaces.
|
||||
tag_name, arg = token.contents.split(None, 1)
|
||||
except ValueError:
|
||||
raise TemplateSyntaxError('%r tag requires arguments' % token.contents.split()[0])
|
||||
m = re.search(r'(.*?) as (\w+)', arg)
|
||||
if not m:
|
||||
raise TemplateSyntaxError('%r tag had invalid arguments' % tag_name)
|
||||
format_string, var_name = m.groups()
|
||||
if not (format_string[0] == format_string[-1] and format_string[0] in ('"', "'")):
|
||||
raise TemplateSyntaxError('%r tag\'s argument should be in quotes' % tag_name)
|
||||
return SettingsNode(format_string[1:-1], var_name)
|
||||
Reference in New Issue
Block a user