+class UnlinkedPOSTCHKUploader(UploadResultsRendererMixin, rend.Page):
+ """'POST /uri', to create an unlinked file."""
+ docFactory = getxmlfile("upload-results.xhtml")
+
+ def __init__(self, client, req):
+ rend.Page.__init__(self)
+ # we start the upload now, and distribute notification of its
+ # completion to render_ methods with an ObserverList
+ assert req.method == "POST"
+ self._done = observer.OneShotObserverList()
+ fileobj = req.fields["file"].file
+ uploadable = FileHandle(fileobj)
+ d = client.upload(uploadable)
+ d.addBoth(self._done.fire)
+
+ def renderHTTP(self, ctx):
+ req = inevow.IRequest(ctx)
+ when_done = get_arg(req, "when_done", None)
+ if when_done:
+ # if when_done= is provided, return a redirect instead of our
+ # usual upload-results page
+ d = self._done.when_fired()
+ d.addCallback(lambda res: url.URL.fromString(when_done))
+ return d
+ return rend.Page.renderHTTP(self, ctx)
+
+ def upload_results(self):
+ return self._done.when_fired()
+
+ def data_done(self, ctx, data):
+ d = self.upload_results()
+ d.addCallback(lambda res: "done!")
+ return d
+
+ def data_uri(self, ctx, data):
+ d = self.upload_results()
+ d.addCallback(lambda res: res.uri)
+ return d
+
+ def render_download_link(self, ctx, data):
+ d = self.upload_results()
+ d.addCallback(lambda res: T.a(href="/uri/" + urllib.quote(res.uri))
+ ["/uri/" + res.uri])
+ return d
+