Skip to content

Commit

Permalink
Merge branch '0.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt committed Mar 26, 2012
2 parents 5be955e + 27ef604 commit 8ecd4c9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion concepts/__init__.py
Expand Up @@ -4,7 +4,7 @@
__version_info__ = {
'major': 0,
'minor': 3,
'micro': 1,
'micro': 2,
'releaselevel': 'final',
'serial': 1
}
Expand Down
Empty file.
37 changes: 37 additions & 0 deletions concepts/templatetags/concepts_tags.py
@@ -0,0 +1,37 @@
from django import template
from django.core.exceptions import FieldError

from concepts.models import ConceptItem, Concept
from django.contrib.contenttypes.models import ContentType

register = template.Library()


class ConceptsNode(template.Node):
"""
Sets a context variable to the concepts linked to the object
"""
def __init__(self, obj, variable_name):
self.obj = template.Variable(obj)
self.variable_name = variable_name

def render(self, context):
obj = self.obj.resolve(context)
ctype = ContentType.objects.get_for_model(obj)
links = ConceptItem.objects.filter(object_id=obj.pk, content_type=ctype)
context[self.variable_name] = links
return ''

@register.tag
def get_concepts_for_object(parser, token):
"""
Get the concepts linked to the object instance passed
{% get_concepts_for_object object as var %}
"""
bits = token.split_contents()

if len(bits) != 4:
raise template.TemplateSyntaxError("The proper usage is: {%% get_concepts_for_object object as var %}")

return ConceptsNode(bits[1], bits[3])

0 comments on commit 8ecd4c9

Please sign in to comment.