- self.set_header("Content-Type", "text/html")
-
- displaypath = cgi.escape(path)
- self.write("""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Directory listing for %(displaypath)s</title>
- <style type="text/css">
- body, table { font-family: sans-serif }
- #breadcrumb { margin: 10px 0; }
- .dir-name { text-align: left }
- .dir-size { text-align: right }
- </style>
- </head>
- <body>
- <div id="breadcrumb">
-""" % { 'displaypath': displaypath })
- if path == "/":
- self.write("""<strong>[root]</strong>""")
- else:
- self.write("""<a href="/">[root]</a> """)
- path_parts = path.split("/")
- path_parts_cleaned = path_parts[1:-1]
- for index, value in enumerate(path_parts_cleaned[0:-1]):
- self.write("""/ <a href="/%(path)s/">%(element)s</a> """ % { 'path' : "/".join(path_parts_cleaned[0:(index + 1)]) , 'element' : value})
- self.write("""/ <strong>%s</strong>""" % path_parts_cleaned[-1])
- self.write("""
- </div>
- <table>
- <tr>
- <th class="dir-name">Name</th>
- <th class="dir-size">Size</th>
- </tr>
-""")
- for sub in n:
- displayname = linkname = sub.name
- # Append / for directories or @ for symbolic links
- size = str(sub.size())
- if stat.S_ISDIR(sub.mode):
- displayname = sub.name + "/"
- linkname = sub.name + "/"
- size = ' '
- if stat.S_ISLNK(sub.mode):
- displayname = sub.name + "@"
- # Note: a link to a directory displays with @ and links with /
- size = ' '
- self.write(""" <tr>
- <td class="dir-name"><a href="%s">%s</a></td>
- <td class="dir-size">%s</td>
- </tr>""" % (urllib.quote(linkname), cgi.escape(displayname), size))
- self.write("""
- </table>
- </body>
-</html>""")
+ try:
+ show_hidden = int(self.request.arguments.get('hidden', [0])[-1])
+ except ValueError, e:
+ show_hidden = False
+
+ self.render(
+ 'list-directory.html',
+ path=path,
+ breadcrumbs=_compute_breadcrumbs(path, show_hidden),
+ files_hidden=_contains_hidden_files(n),
+ hidden_shown=show_hidden,
+ dir_contents=_compute_dir_contents(n, path, show_hidden))