From: Brian Warner Date: Sat, 14 Jul 2007 06:45:35 +0000 (-0700) Subject: webish.Directory: add a 'text/plain' link for files, to download as plaintext. X-Git-Url: https://git.rkrishnan.org/pf/content/en/service/contact.html?a=commitdiff_plain;h=7bc031a81d6830b225a32b1d2f709ffd35d33e68;p=tahoe-lafs%2Ftahoe-lafs.git webish.Directory: add a 'text/plain' link for files, to download as plaintext. 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. --- diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index 7e6ddac4..94b89a6d 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -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