Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello, changed ContextSetterNode resolution, now it's possible to use filters. #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 4 additions & 14 deletions disqus/templatetags/disqus_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django import template
from django.conf import settings
from django.contrib.sites.models import Site
from django.template.base import FilterExpression
from django.utils.functional import curry
from django.utils.encoding import force_unicode

Expand All @@ -11,22 +12,11 @@ def __init__(self, var_name, var_value):
self.var_name = var_name
self.var_value = var_value

def _get_value(self, value, context):
"""
Attempts to resolve the value as a variable. Failing that, it returns
its actual value
"""
try:
var_value = template.Variable(value).resolve(context)
except template.VariableDoesNotExist:
var_value = self.var_value.var
return var_value

def render(self, context):
if isinstance(self.var_value, (list, tuple)):
var_value = ''.join([force_unicode(self._get_value(x, context)) for x in self.var_value])
var_value = ''.join([x.resolve(context, ignore_failures=True) for x in self.var_value])
else:
var_value = self._get_value(self.var_value, context)
var_value = self.var_value.resolve(context, ignore_failures=True)
context[self.var_name] = var_value
return ''

Expand All @@ -40,7 +30,7 @@ def generic_setter_compiler(var_name, name, node_class, parser, token):
if(len(bits) < 2):
message = "%s takes at least one argument" % name
raise template.TemplateSyntaxError(message)
return node_class(var_name, bits[1:])
return node_class(var_name, [FilterExpression(bit, parser) for bit in bits[1:]])

# Set the disqus_developer variable to 0/1. Default is 0
set_disqus_developer = curry(generic_setter_compiler, 'disqus_developer', 'set_disqus_developer', ContextSetterNode)
Expand Down