Permalink
Browse files

Adding a filter that returns the app_label of an object.

  • Loading branch information...
1 parent a693c95 commit 87fcbcad692dcde2636bb25a4ac59bbd188edb5a @nathanborror committed Aug 13, 2010
Showing with 19 additions and 4 deletions.
  1. +19 −4 basic/tools/templatetags/comparison.py
@@ -3,21 +3,36 @@
register = Library()
+
@register.filter
def is_content_type(obj, arg):
try:
ct = lower(obj._meta.object_name)
return ct == arg
except AttributeError:
- return ""
+ return ''
+
+
+@register.filter
+def app_label(obj):
+ """
+ Returns an objects app label.
+ """
+ try:
+ return lower(obj._meta.object_name)
+ except AttributeError:
+ return ''
+
@register.filter
def round(obj):
- "Returns a number rounded."
+ """
+ Returns a number rounded.
+ """
try:
return round(obj)
except (ValueError,TypeError):
- return ""
+ return ''
@register.filter
@@ -36,6 +51,6 @@ def get_vars(obj):
if 'page' in obj:
del getvars['page']
if len(getvars.keys()) > 0:
- return "&%s" % getvars.urlencode()
+ return '&%s' % getvars.urlencode()
else:
return ''

0 comments on commit 87fcbca

Please sign in to comment.