Merge pull request #727 from sajith/3315.operations-reload-mixin-nevow-to-twisted

Replace nevow with twisted.web in operations.ReloadMixin

Fixes: ticket:3315
This commit is contained in:
Sajith Sasidharan 2020-06-16 19:17:27 -04:00 committed by GitHub
commit fe967d208b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 16 deletions

1
newsfragments/3315.minor Normal file
View File

@ -0,0 +1 @@
Replace nevow with twisted.web in web.operations.ReloadMixin

View File

@ -1,7 +1,11 @@
import time
from nevow import rend, url, tags as T
from nevow import rend, url
from nevow.inevow import IRequest
from twisted.web.template import (
renderer,
tags as T,
)
from twisted.python.failure import Failure
from twisted.internet import reactor, defer
from twisted.web.http import NOT_FOUND
@ -122,31 +126,31 @@ class OphandleTable(rend.Page, service.Service):
class ReloadMixin(object):
REFRESH_TIME = 1*MINUTE
def render_refresh(self, ctx, data):
@renderer
def refresh(self, req, tag):
if self.monitor.is_finished():
return ""
# dreid suggests ctx.tag(**dict([("http-equiv", "refresh")]))
# but I can't tell if he's joking or not
ctx.tag.attributes["http-equiv"] = "refresh"
ctx.tag.attributes["content"] = str(self.REFRESH_TIME)
return ctx.tag
tag.attributes["http-equiv"] = "refresh"
tag.attributes["content"] = str(self.REFRESH_TIME)
return tag
def render_reload(self, ctx, data):
@renderer
def reload(self, req, tag):
if self.monitor.is_finished():
return ""
req = IRequest(ctx)
# url.gethere would break a proxy, so the correct thing to do is
# req.path[-1] + queryargs
ophandle = req.prepath[-1]
reload_target = ophandle + "?output=html"
cancel_target = ophandle + "?t=cancel"
cancel_button = T.form(action=cancel_target, method="POST",
enctype="multipart/form-data")[
T.input(type="submit", value="Cancel"),
]
cancel_button = T.form(T.input(type="submit", value="Cancel"),
action=cancel_target,
method="POST",
enctype="multipart/form-data",)
return [T.h2["Operation still running: ",
T.a(href=reload_target)["Reload"],
],
cancel_button,
]
return (T.h2("Operation still running: ",
T.a("Reload", href=reload_target),
),
cancel_button,)