mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-26 14:19:32 +00:00
Make DownloadStatusPage a MultiFormatResource
This commit is contained in:
parent
8a632b6668
commit
c14c437152
@ -489,13 +489,25 @@ class _EventJson(Resource, object):
|
|||||||
return json.dumps(data, indent=1) + "\n"
|
return json.dumps(data, indent=1) + "\n"
|
||||||
|
|
||||||
|
|
||||||
class DownloadStatusPage(DownloadResultsRendererMixin, rend.Page):
|
class DownloadStatusPage(MultiFormatResource):
|
||||||
docFactory = getxmlfile("download-status.xhtml")
|
|
||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, download_status):
|
||||||
rend.Page.__init__(self, data)
|
super(DownloadStatusPage, self).__init__()
|
||||||
self.download_status = data
|
self._download_status = download_status
|
||||||
self.putChild("event_json", _EventJson(self.download_status))
|
self.putChild("event_json", _EventJson(self._download_status))
|
||||||
|
|
||||||
|
def render_HTML(self, req):
|
||||||
|
elem = DownloadStatusElement(self._download_status)
|
||||||
|
return renderElement(req, elem)
|
||||||
|
|
||||||
|
|
||||||
|
class DownloadStatusElement(Element, DownloadResultsRendererMixin):
|
||||||
|
|
||||||
|
loader = XMLFile(FilePath(__file__).sibling("download-status.xhtml"))
|
||||||
|
|
||||||
|
def __init__(self, download_status):
|
||||||
|
super(DownloadStatusElement, self).__init__()
|
||||||
|
self._download_status = download_status
|
||||||
|
|
||||||
def download_results(self):
|
def download_results(self):
|
||||||
return defer.maybeDeferred(self.download_status.get_results)
|
return defer.maybeDeferred(self.download_status.get_results)
|
||||||
@ -645,33 +657,40 @@ class DownloadStatusPage(DownloadResultsRendererMixin, rend.Page):
|
|||||||
d.addCallback(_got_results)
|
d.addCallback(_got_results)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def render_started(self, ctx, data):
|
@renderer
|
||||||
started_s = render_time(data.get_started())
|
def started(self, req, tag):
|
||||||
return started_s + " (%s)" % data.get_started()
|
started_s = render_time(self._download_status.get_started())
|
||||||
|
return tag(started_s + " (%s)" % self._download_status.get_started())
|
||||||
|
|
||||||
def render_si(self, ctx, data):
|
@renderer
|
||||||
si_s = base32.b2a_or_none(data.get_storage_index())
|
def si(self, req, tag):
|
||||||
|
si_s = base32.b2a_or_none(self._download_status.get_storage_index())
|
||||||
if si_s is None:
|
if si_s is None:
|
||||||
si_s = "(None)"
|
si_s = "(None)"
|
||||||
return si_s
|
return tag(si_s)
|
||||||
|
|
||||||
def render_helper(self, ctx, data):
|
@renderer
|
||||||
return {True: "Yes",
|
def helper(self, req, tag):
|
||||||
False: "No"}[data.using_helper()]
|
return tag({True: "Yes",
|
||||||
|
False: "No"}[self._download_status.using_helper()])
|
||||||
|
|
||||||
def render_total_size(self, ctx, data):
|
@renderer
|
||||||
size = data.get_size()
|
def total_size(self, req, tag):
|
||||||
|
size = self._download_status.get_size()
|
||||||
if size is None:
|
if size is None:
|
||||||
return "(unknown)"
|
return "(unknown)"
|
||||||
return size
|
return tag(str(size))
|
||||||
|
|
||||||
def render_progress(self, ctx, data):
|
@renderer
|
||||||
progress = data.get_progress()
|
def progress(self, req, tag):
|
||||||
|
progress = self._download_status.get_progress()
|
||||||
# TODO: make an ascii-art bar
|
# TODO: make an ascii-art bar
|
||||||
return "%.1f%%" % (100.0 * progress)
|
return tag("%.1f%%" % (100.0 * progress))
|
||||||
|
|
||||||
|
@renderer
|
||||||
|
def status(self, req, tag):
|
||||||
|
return tag(self._download_status.get_status())
|
||||||
|
|
||||||
def render_status(self, ctx, data):
|
|
||||||
return data.get_status()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user