Make UploadStatusPage a MultiFormatResource

This commit is contained in:
Sajith Sasidharan 2020-05-18 17:08:31 -04:00 committed by Sajith Sasidharan
parent d24babe873
commit e6f0f9d038

View File

@ -169,62 +169,85 @@ class UploadResultsRendererMixin(RateAndTimeMixin):
d.addCallback(_convert) d.addCallback(_convert)
return d return d
class UploadStatusPage(UploadResultsRendererMixin, rend.Page):
docFactory = getxmlfile("upload-status.xhtml")
def __init__(self, data): class UploadStatusPage(MultiFormatResource):
rend.Page.__init__(self, data)
self.upload_status = data def __init__(self, upload_status):
super(UploadStatusPage, self).__init__()
self._upload_status = upload_status
def render_HTML(self, req):
elem = UploadStatusElement(self._upload_status)
return renderElement(req, elem)
class UploadStatusElement(Element, UploadResultsRendererMixin):
loader = XMLFile(FilePath(__file__).sibling("upload-status.xhtml"))
def __init__(self, upload_status):
super(UploadStatusElement, self).__init__()
self._upload_status = upload_status
def upload_results(self): def upload_results(self):
return defer.maybeDeferred(self.upload_status.get_results) return defer.maybeDeferred(self._upload_status.get_results)
def render_results(self, ctx, data): @renderer
def results(self, req, tag):
d = self.upload_results() d = self.upload_results()
def _got_results(results): def _got_results(results):
if results: if results:
return ctx.tag return tag
return "" return ""
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 started_s = render_time(self._upload_status.get_started())
return tag(started_s)
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._upload_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(str(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._upload_status.using_helper()])
def render_total_size(self, ctx, data): @renderer
size = data.get_size() def total_size(self, req, tag):
size = self._upload_status.get_size()
if size is None: if size is None:
return "(unknown)" return "(unknown)"
return size return tag(str(size))
def render_progress_hash(self, ctx, data): @renderer
progress = data.get_progress()[0] def progress_hash(self, req, tag):
progress = self._upload_status.get_progress()[0]
# TODO: make an ascii-art bar
return tag("%.1f%%" % (100.0 * progress))
@renderer
def progress_ciphertext(self, req, tag):
progress = self._upload_status.get_progress()[1]
# TODO: make an ascii-art bar # TODO: make an ascii-art bar
return "%.1f%%" % (100.0 * progress) return "%.1f%%" % (100.0 * progress)
def render_progress_ciphertext(self, ctx, data): @renderer
progress = data.get_progress()[1] def progress_encode_push(self, req, tag):
progress = self._upload_status.get_progress()[2]
# TODO: make an ascii-art bar # TODO: make an ascii-art bar
return "%.1f%%" % (100.0 * progress) return tag("%.1f%%" % (100.0 * progress))
def render_progress_encode_push(self, ctx, data): @renderer
progress = data.get_progress()[2] def status(self, req, tag):
# TODO: make an ascii-art bar return tag(self._upload_status.get_status())
return "%.1f%%" % (100.0 * progress)
def render_status(self, ctx, data):
return data.get_status()
class DownloadResultsRendererMixin(RateAndTimeMixin): class DownloadResultsRendererMixin(RateAndTimeMixin):
# this requires a method named 'download_results' # this requires a method named 'download_results'