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.
This commit is contained in:
Brian Warner 2007-07-13 23:45:35 -07:00
parent 225fbfee57
commit 7bc031a81d

View 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