Convert storage.py over to MultiFormatPage

This commit is contained in:
Jean-Paul Calderone 2017-07-25 11:16:38 -04:00
parent 6e4c4b7abc
commit 1e885fa40b

View File

@ -1,7 +1,11 @@
import time, json import time, json
from nevow import rend, tags as T, inevow from nevow import rend, tags as T
from allmydata.web.common import getxmlfile, abbreviate_time, get_arg from allmydata.web.common import (
getxmlfile,
abbreviate_time,
MultiFormatPage,
)
from allmydata.util.abbreviate import abbreviate_space from allmydata.util.abbreviate import abbreviate_space
from allmydata.util import time_format, idlib from allmydata.util import time_format, idlib
@ -10,7 +14,7 @@ def remove_prefix(s, prefix):
return None return None
return s[len(prefix):] return s[len(prefix):]
class StorageStatus(rend.Page): class StorageStatus(MultiFormatPage):
docFactory = getxmlfile("storage_status.xhtml") docFactory = getxmlfile("storage_status.xhtml")
# the default 'data' argument is the StorageServer instance # the default 'data' argument is the StorageServer instance
@ -19,13 +23,6 @@ class StorageStatus(rend.Page):
self.storage = storage self.storage = storage
self.nickname = nickname self.nickname = nickname
def renderHTTP(self, ctx):
req = inevow.IRequest(ctx)
t = get_arg(req, "t")
if t == "json":
return self.render_JSON(req)
return rend.Page.renderHTTP(self, ctx)
def render_JSON(self, req): def render_JSON(self, req):
req.setHeader("content-type", "text/plain") req.setHeader("content-type", "text/plain")
d = {"stats": self.storage.get_stats(), d = {"stats": self.storage.get_stats(),
@ -266,4 +263,3 @@ class StorageStatus(rend.Page):
]]]) ]]])
return ctx.tag[p] return ctx.tag[p]