mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-12 16:02:43 +00:00
Make LiteralCheckResultsRenderer a MultiFormatResource
This commit is contained in:
parent
ebf23a4f0e
commit
3901559e34
@ -10,11 +10,20 @@ from twisted.web import (
|
|||||||
http,
|
http,
|
||||||
html,
|
html,
|
||||||
)
|
)
|
||||||
|
from twisted.python.filepath import FilePath
|
||||||
|
from twisted.web.template import (
|
||||||
|
Element,
|
||||||
|
XMLFile,
|
||||||
|
renderer,
|
||||||
|
renderElement,
|
||||||
|
tags,
|
||||||
|
)
|
||||||
from allmydata.web.common import (
|
from allmydata.web.common import (
|
||||||
getxmlfile,
|
getxmlfile,
|
||||||
get_arg,
|
get_arg,
|
||||||
get_root,
|
get_root,
|
||||||
WebError,
|
WebError,
|
||||||
|
MultiFormatResource,
|
||||||
)
|
)
|
||||||
from allmydata.web.operations import ReloadMixin
|
from allmydata.web.operations import ReloadMixin
|
||||||
from allmydata.interfaces import (
|
from allmydata.interfaces import (
|
||||||
@ -199,30 +208,37 @@ class ResultsBase(object):
|
|||||||
target = target + "?output=%s" % output
|
target = target + "?output=%s" % output
|
||||||
return T.a(href=target)[si_s]
|
return T.a(href=target)[si_s]
|
||||||
|
|
||||||
class LiteralCheckResultsRenderer(rend.Page, ResultsBase):
|
|
||||||
docFactory = getxmlfile("literal-check-results.xhtml")
|
class LiteralCheckResultsRenderer(MultiFormatResource, ResultsBase):
|
||||||
|
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
|
super(LiteralCheckResultsRenderer, self).__init__()
|
||||||
self.client = client
|
self.client = client
|
||||||
rend.Page.__init__(self, client)
|
|
||||||
|
|
||||||
def renderHTTP(self, ctx):
|
def render_HTML(self, req):
|
||||||
if self.want_json(ctx):
|
return renderElement(req, LiteralCheckResultsElement())
|
||||||
return self.json(ctx)
|
|
||||||
return rend.Page.renderHTTP(self, ctx)
|
|
||||||
|
|
||||||
def json(self, ctx):
|
def render_JSON(self, req):
|
||||||
inevow.IRequest(ctx).setHeader("content-type", "text/plain")
|
req.setHeader("content-type", "text/plain")
|
||||||
data = json_check_results(None)
|
data = json_check_results(None)
|
||||||
return json.dumps(data, indent=1) + "\n"
|
return json.dumps(data, indent=1) + "\n"
|
||||||
|
|
||||||
def render_return(self, ctx, data):
|
|
||||||
req = inevow.IRequest(ctx)
|
class LiteralCheckResultsElement(Element):
|
||||||
|
|
||||||
|
loader = XMLFile(FilePath(__file__).sibling("literal-check-results.xhtml"))
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(LiteralCheckResultsElement, self).__init__()
|
||||||
|
|
||||||
|
@renderer
|
||||||
|
def return(self, req, tag):
|
||||||
return_to = get_arg(req, "return_to", None)
|
return_to = get_arg(req, "return_to", None)
|
||||||
if return_to:
|
if return_to:
|
||||||
return T.div[T.a(href=return_to)["Return to file."]]
|
return tags.div(tags.a("Return to file.", href=return_to))
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
class CheckerBase(object):
|
class CheckerBase(object):
|
||||||
|
|
||||||
def renderHTTP(self, ctx):
|
def renderHTTP(self, ctx):
|
||||||
|
Loading…
Reference in New Issue
Block a user