For readability in this sort of complicated js-within-python, use string templates instead of string formatting.  See http://docs.python.org/2/library/string.html#template-strings