Commits

Anonymous committed b3ca662

Tidyup template tag code. Also, try to fix tag filtering

Comments (0)

Files changed (1)

gnocchi/blog/templatetags/blog.py

 from django import template
+from django.template.base import FilterExpression
 from gnocchi.blog.models import Post
 from gnocchi.tools.template import parse_args
 
         self.tags = tags
         self.username = username
     def render(self, context):
+        def resolve(var):
+            if isinstance(var, FilterExpression):
+                return var.resolve(context)
+            return var
+
         count = self.count.resolve(context)
+
         tags = filter(None, [tag.resolve(context) for tag in self.tags])
-        varname = self.varname
-        if not isinstance(varname, basestring):
-            varname = varname.resolve(context)
-        username = self.username
-        if username and not isinstance(username, basestring):
-            username = username.resolve(context)
+
+        varname = resolve(self.varname)
+        username = resolve(self.username)
 
         qset = Post.objects.current()
         if tags:
-            qset = qset.filter(tag__in=tags)
+            qset = qset.filter(tag__name__in=tags)
         if username:
             qset = qset.filter(posted_by__username=username)
         context[varname] = qset[:count]