From 7bc031a81d6830b225a32b1d2f709ffd35d33e68 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 13 Jul 2007 23:45:35 -0700 Subject: [PATCH] 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. --- src/allmydata/webish.py | 7 +++++++ 1 file changed, 7 insertions(+) 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 -- 2.45.2