Ticket #16601: django-tabindex-filter.py

File django-tabindex-filter.py, 747 bytes (added by mike@…, 13 years ago)

A tabindex filter

Line 
1from django import template
2from django.template.defaultfilters import stringfilter
3from django.utils.safestring import mark_safe
4
5register = template.Library()
6
7@register.filter
8@stringfilter
9def tabindex(widget, index):
10 if isinstance(index, int):
11 if widget.find('/>') != -1:
12 retval = widget.replace('/>', ' tabindex="{0}" />'.format(index))
13 return mark_safe(retval)
14 elif widget.find('>') != -1:
15 retval = widget.replace('>', ' tabindex="{0}">'.format(index))
16 return mark_safe(retval)
17 else:
18 return mark_safe(widget)
19
20 try:
21 ind = int(index)
22 return tabindex(widget, index)
23 except:
24 return mark_safe(widget)
25tabindex.is_safe = True
Back to Top