Skip to content
Browse files

Adding flagged_with filter to flagging app. Thanks coleifer.

  • Loading branch information...
1 parent c9e15ca commit 216d61ed56b19055f7192ee54b34677f846be05c @nathanborror committed Aug 17, 2010
Showing with 15 additions and 0 deletions.
  1. +15 −0 basic/flagging/templatetags/flagging.py
View
15 basic/flagging/templatetags/flagging.py
@@ -49,6 +49,21 @@ def unflag_url(obj, slug):
})
+@register.filter
+def flagged_with(obj, slug):
+ """
+ Returns true of false based on whether the object is flagged one or more
+ times with a particular flag type.
+ """
+ content_type = ContentType.objects.get_for_model(obj)
+ flags = Flag.objects.filter(
+ flag_type__slug=slug,
+ content_type=content_type,
+ object_id=obj.pk
+ )
+ return flags.count() != 0
+
+
class GetFlags(template.Node):
def __init__(self, object_name, user, slug, varname):
self.object_name = object_name

0 comments on commit 216d61e

Please sign in to comment.
Something went wrong with that request. Please try again.