]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
webish.Directory: add a 'text/plain' link for files, to download as plaintext.
authorBrian Warner <warner@lothar.com>
Sat, 14 Jul 2007 06:45:35 +0000 (23:45 -0700)
committerBrian Warner <warner@lothar.com>
Sat, 14 Jul 2007 06:45:35 +0000 (23:45 -0700)
This is useful to view (e.g.) .py files that would otherwise be served as
some weird text/x-python that browsers will just want to save to disk.

src/allmydata/webish.py

index 7e6ddac4173c653b02eeeb90feaf4b4ff88a762e..94b89a6d9334571ab4e5fa1985280f9e61127b51 100644 (file)
@@ -117,6 +117,9 @@ class Directory(rend.Page):
                 size = "?"
             ctx.fillSlots("size", size)
 
+            text_plain_link = "/uri/%s?filename=foo.txt" % uri_link
+            text_plain_tag = T.a(href=text_plain_link)["text/plain"]
+
             # if we're a file, add the filename to the uri_link url
             uri_link += '?%s' % (urllib.urlencode({'filename': name}),)
 
@@ -131,6 +134,7 @@ class Directory(rend.Page):
                 dirtype = "DIR-RO"
             ctx.fillSlots("type", dirtype)
             ctx.fillSlots("size", "-")
+            text_plain_tag = None
         else:
             raise RuntimeError("unknown thing %s" % (target,))
 
@@ -139,6 +143,9 @@ class Directory(rend.Page):
                      T.a(href="%s?t=readonly-uri" % name)["readonly-URI"], ", ",
                      T.a(href="/uri/%s" % uri_link)["URI-link"],
                      ]
+        if text_plain_tag:
+            childdata.extend([", ", text_plain_tag])
+
         ctx.fillSlots("data", childdata)
 
         return ctx.tag