Commits

Chris Moffitt  committed 9532066 Draft Merge

Merged in Lacrymology/satchmo/0.9.2 (pull request #41)

  • Participants
  • Parent commits cf857da, 0f59c03

Comments (0)

Files changed (1)

File satchmo/apps/satchmo_store/shop/templatetags/satchmo_category.py

 from django.contrib.sites.models import Site
 from django.template import Library, Node, Variable
 from django.template import TemplateSyntaxError, VariableDoesNotExist
-from product.models import Category
+from product.models import Category, CategoryAttribute
 from satchmo_utils.templatetags import get_filter_args
 from django.utils.translation import get_language
 
 
     raise TemplateSyntaxError, "Invalid arguments for %r tag" \
           % tag_name
+
+@register.filter
+def attribute(category, attr_name):
+    """
+    usage: {{ category|attribute:"attr-name" }} prints the attribute named
+    `attr-name`'s value
+    """
+    try:
+        return category.categoryattribute_set.get(option__name=attr_name).value
+    except CategoryAttribute.DoesNotExist:
+        return ""