Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. def add_script(req, filename, mimetype='text/javascript'):
  2.     """Add a reference to an external javascript file to the template.
  3.    
  4.    If the filename is absolute (i.e. starts with a slash), the generated link
  5.    will be based off the application root path. If it is relative, the link
  6.    will be based off the `/chrome/` path.
  7.    """
  8.     scriptset = req.chrome.setdefault('scriptset', set())
  9.     if filename in scriptset:
  10.         return False # Already added that script
  11.  
  12.     if filename.startswith('common/') and 'htdocs_location' in req.chrome:
  13.         href = Href(req.chrome['htdocs_location'])
  14.         path = filename[7:]
  15.     else:
  16.         href = req.href
  17.         if not filename.startswith('/'):
  18.             href = href.chrome
  19.         path = filename
  20.     script = {'href': href(path), 'type': mimetype}
  21.  
  22.     req.chrome.setdefault('scripts', []).append(script)
  23.     scriptset.add(filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement