Allow setting of tabindex in presentation layer
|Design decision needed
|Patch needs improvement:
I needed this for a project that I was working on, and I thought I would put the function here. I am a very new Django user and haven't so much as looked at its source code yet, but if I can get to it after my current project is finished, I'll be happy to contribute this as a proper patch if desired.
Essentially, this is a filter for use on form fields, links, etc. in order to add a tabindex attribute to it. In order to remain light, it doesn't call up an HTML parser, and so it naïvely appends tabindex="X" to the end of the list of attributes. It handles both /> and normal > tag closure, so that it works for both types of tags. If it cannot find an end-of-tag, it returns the input unaltered. Furthermore, if the tabindex parameter is passed in as a string it will attempt conversion to an integer; if that fails, it will also return the input as-is.