diff options
author | Nicolás Reynolds <fauno@kiwwwi.com.ar> | 2011-05-21 02:11:13 -0300 |
---|---|---|
committer | Nicolás Reynolds <fauno@kiwwwi.com.ar> | 2011-05-21 02:11:13 -0300 |
commit | a30350ac6e76c66d14f6d78ed2b5ae4e5799c79c (patch) | |
tree | a2b7127366a1b9d8d5be9fcda5abefacef7d2579 /main/templatetags | |
parent | d8f82d9d72eec6042536797f75e06a9296f4cc71 (diff) | |
parent | 2470c543d60c96343a5b0fefe04464b5b445b859 (diff) |
Merge branch 'master' of git://projects.archlinux.org/archweb
Conflicts:
devel/views.py
feeds.py
templates/devel/index.html
templates/packages/flag.html
templates/public/index.html
todolists/views.py
urls.py
Diffstat (limited to 'main/templatetags')
-rw-r--r-- | main/templatetags/attributes.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/main/templatetags/attributes.py b/main/templatetags/attributes.py new file mode 100644 index 00000000..bd4ccf3d --- /dev/null +++ b/main/templatetags/attributes.py @@ -0,0 +1,21 @@ +import re +from django import template +from django.conf import settings + +numeric_test = re.compile("^\d+$") +register = template.Library() + +def attribute(value, arg): + """Gets an attribute of an object dynamically from a string name""" + if hasattr(value, str(arg)): + return getattr(value, arg) + elif hasattr(value, 'has_key') and value.has_key(arg): + return value[arg] + elif numeric_test.match(str(arg)) and len(value) > int(arg): + return value[int(arg)] + else: + return settings.TEMPLATE_STRING_IF_INVALID + +register.filter('attribute', attribute) + +# vim: set ts=4 sw=4 et: |