mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-23 14:52:26 +00:00
Avoid use of deferred within an Element
This causes the final HTML to be rendered funny, with a bunch of "<Deferred current result=...>", which is clearly not what we want.
This commit is contained in:
parent
7877d8a5cc
commit
0c4d24a2ac
@ -439,7 +439,7 @@ class DownloadStatusElement(Element):
|
||||
#
|
||||
# See #3310: https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3310
|
||||
def download_results(self):
|
||||
return defer.maybeDeferred(self._download_status.get_results)
|
||||
return self._download_status.get_results()
|
||||
|
||||
def _relative_time(self, t):
|
||||
if t is None:
|
||||
@ -629,13 +629,9 @@ class DownloadStatusElement(Element):
|
||||
|
||||
@renderer
|
||||
def results(self, req, tag):
|
||||
d = self.download_results()
|
||||
def _got_results(results):
|
||||
if results:
|
||||
if self.download_results():
|
||||
return tag
|
||||
return ""
|
||||
d.addCallback(_got_results)
|
||||
return d
|
||||
|
||||
@renderer
|
||||
def started(self, req, tag):
|
||||
@ -673,23 +669,19 @@ class DownloadStatusElement(Element):
|
||||
|
||||
@renderer
|
||||
def servers_used(self, req, tag):
|
||||
d = self.download_results()
|
||||
d.addCallback(lambda res: res.servers_used)
|
||||
def _got(servers_used):
|
||||
servers_used = self.download_results().servers_used
|
||||
|
||||
if not servers_used:
|
||||
return ""
|
||||
|
||||
peerids_s = ", ".join(["[%s]" % idlib.shortnodeid_b2a(peerid)
|
||||
for peerid in servers_used])
|
||||
return tags.li("Servers Used: ", peerids_s)
|
||||
d.addCallback(_got)
|
||||
return d
|
||||
|
||||
@renderer
|
||||
def servermap(self, req, tag):
|
||||
d = self.download_results()
|
||||
d.addCallback(lambda res: res.servermap)
|
||||
def _render(servermap):
|
||||
if servermap is None:
|
||||
servermap = self.download_results().servermap
|
||||
if not servermap:
|
||||
return tag("None")
|
||||
ul = tags.ul()
|
||||
for peerid in sorted(servermap.keys()):
|
||||
@ -700,34 +692,24 @@ class DownloadStatusElement(Element):
|
||||
plural(servermap[peerid]),
|
||||
shares_s)))
|
||||
return ul
|
||||
d.addCallback(_render)
|
||||
return d
|
||||
|
||||
@renderer
|
||||
def problems(self, req, tag):
|
||||
d = self.download_results()
|
||||
d.addCallback(lambda res: res.server_problems)
|
||||
def _got(server_problems):
|
||||
server_problems = self.download_results().server_problems
|
||||
if not server_problems:
|
||||
return tag("")
|
||||
return ""
|
||||
ul = T.ul()
|
||||
for peerid in sorted(server_problems.keys()):
|
||||
peerid_s = idlib.shortnodeid_b2a(peerid)
|
||||
ul(tags.li("[%s]: %s" % (peerid_s, server_problems[peerid])))
|
||||
return tags.li("Server Problems:", ul)
|
||||
d.addCallback(_got)
|
||||
return d
|
||||
|
||||
@renderer
|
||||
def file_size(self, req, tag):
|
||||
d = self.download_results()
|
||||
d.addCallback(lambda res: str(res.file_size))
|
||||
return d
|
||||
return tag(str(self.download_results().file_size))
|
||||
|
||||
def _get_time(self, name):
|
||||
d = self.download_results()
|
||||
d.addCallback(lambda res: res.timings.get(name))
|
||||
return d
|
||||
return self.download_results().timings.get(name)
|
||||
|
||||
@renderer
|
||||
def time_total(self, req, tag):
|
||||
@ -766,13 +748,10 @@ class DownloadStatusElement(Element):
|
||||
return tag(str(self._get_time("paused")))
|
||||
|
||||
def _get_rate(self, name):
|
||||
d = self.download_results()
|
||||
def _convert(r):
|
||||
r = self.download_results()
|
||||
file_size = r.file_size
|
||||
duration = r.timings.get(name)
|
||||
return compute_rate(file_size, duration)
|
||||
d.addCallback(_convert)
|
||||
return d
|
||||
|
||||
@renderer
|
||||
def rate_total(self, req, tag):
|
||||
@ -796,9 +775,7 @@ class DownloadStatusElement(Element):
|
||||
|
||||
@renderer
|
||||
def server_timings(self, req, tag):
|
||||
d = self.download_results()
|
||||
d.addCallback(lambda res: res.timings.get("fetch_per_server"))
|
||||
def _render(per_server):
|
||||
per_server = self._get_time("fetch_per_server")
|
||||
if per_server is None:
|
||||
return ""
|
||||
ul = tags.ul()
|
||||
@ -808,8 +785,6 @@ class DownloadStatusElement(Element):
|
||||
for t in per_server[peerid]])
|
||||
ul(tags.li("[%s]: %s" % (peerid_s, times_s)))
|
||||
return tags.li("Per-Server Segment Fetch Response Times: ", ul)
|
||||
d.addCallback(_render)
|
||||
return d
|
||||
|
||||
|
||||
class RetrieveStatusPage(MultiFormatResource):
|
||||
|
Loading…
Reference in New Issue
Block a user