def render_GET(self, request): email = self.getRequestEmail(request) request.setHeader('content-type', 'text/html; charset=utf-8') element = tags.html( htmlHead, tags.body(tags.form( tags.fieldset( tags.div( tags.label('Cert e-mail'), tags.label('Username', for_='username'), tags.label('Password', for_='password'), tags.label('Site', for_='site', class_='last'), id='names', ), tags.div( tags.input(disabled='true', value=email), tags.input(name='username', type='text'), tags.input(name='password', type='password'), tags.input(name='site', type='url', class_='last'), id='fields', ), ), tags.button('Generate', type='submit'), action='', method='POST', )), ) return renderElement(request, element)
def manifest_form(self, req, tag): ophandle = base32.b2a(os.urandom(16)) manifest = T.form(action=req.path, method="post", enctype="multipart/form-data")(T.fieldset( T.input(type="hidden", name="t", value="start-manifest"), T.legend("Run a manifest operation (EXPENSIVE)", class_="freeform-form-label"), T.div( "Output Format: ", T.select(name="output")( T.option("HTML", value="html", selected="true"), T.option("text", value="text"), T.option("JSON", value="json"), ), ), T.input(type="hidden", name="ophandle", value=ophandle), T.input(type="submit", value="Manifest"), )) return tag(manifest)
def body(self, req): status = self.getStatus(req) authz = self.getAuthz(req) builders = req.args.get( "builder", status.getBuilderNames(categories=self.categories)) branches = [b for b in req.args.get("branch", []) if b] if not branches: branches = ["master"] if branches and "master" not in branches: defaultCount = "1" else: defaultCount = "10" num_builds = int(req.args.get("num_builds", [defaultCount])[0]) tag = tags.div() tag(tags.script(src="hlbb.js")) tag( tags.h2(style="float:left; margin-top:0")("Latest builds: ", ", ".join(branches))) form = tags.form(method="get", action="", style="float:right", onsubmit="return checkBranch(branch.value)") form( tags.input(type="test", name="branch", placeholder=branches[0], size="40")) form(tags.input(type="submit", value="View")) if (yield authz.actionAllowed('forceAllBuilds', req)): # XXX: Unsafe interpolation form( tags.button(type="button", onclick="forceBranch(branch.value || %r, %r)" % ( branches[0], self.categories, ))("Force")) tag(form) table = tags.table(style="clear:both") tag(table) for bn in filter(lambda bn: bn not in self.failing_builders, builders): table(self.builder_row(bn, req, branches, num_builds)) table(tags.tr()(tags.td(colspan="100")( tags.h3(style="float:left; margin-top:0")("Expected failures: ")))) for bn in filter(lambda bn: bn in self.failing_builders, builders): table(self.builder_row(bn, req, branches, num_builds)) defer.returnValue((yield flattenString(req, tag)))
def render_GET(self, request): body = tags.form( tags.label('Tahoe URI', for_='uri'), ' ', tags.input(id='uri', type='text', name='uri'), tags.br(), tags.label('Extension', for_='ext'), ' ', tags.input(id='ext', type='text', name='ext'), tags.br(), tags.input(type='submit', value='Convert to HTTP URL'), action='', method='POST') return renderElement(request, body)
def deep_stats_form(self, req, tag): ophandle = base32.b2a(os.urandom(16)) deep_stats = T.form(action=req.path, method="post", enctype="multipart/form-data")( T.fieldset( T.input(type="hidden", name="t", value="start-deep-stats"), T.legend("Run a deep-stats operation (EXPENSIVE)", class_="freeform-form-label"), T.input(type="hidden", name="ophandle", value=ophandle), T.input(type="submit", value="Deep-Stats"), )) return tag(deep_stats)
def incident_button(self, req, tag): # this button triggers a foolscap-logging "incident" form = tags.form(tags.fieldset( tags.input(type="hidden", name="t", value="report-incident"), "What went wrong?" + SPACE, tags.input(type="text", name="details"), SPACE, tags.input(type="submit", value=u"Save \u00BB"), ), action="report_incident", method="post", enctype="multipart/form-data") return tags.div(form)
def render_GET(self, request): body = tags.form(tags.label('Tahoe URI', for_='uri'), ' ', tags.input(id='uri', type='text', name='uri'), tags.br(), tags.label('Extension', for_='ext'), ' ', tags.input(id='ext', type='text', name='ext'), tags.br(), tags.input(type='submit', value='Convert to HTTP URL'), action='', method='POST') return renderElement(request, body)
def body(self, req): status = self.getStatus(req) authz = self.getAuthz(req) builders = req.args.get( "builder", status.getBuilderNames(categories=self.categories)) branches = [b for b in req.args.get("branch", []) if b] if not branches: branches = ["master"] if branches and "master" not in branches: defaultCount = "1" else: defaultCount = "10" num_builds = int(req.args.get("num_builds", [defaultCount])[0]) tag = tags.div() tag(tags.script(src="hlbb.js")) tag(tags.h2(style="float:left; margin-top:0") ("Latest builds: ", ", ".join(branches))) form = tags.form(method="get", action="", style="float:right", onsubmit="return checkBranch(branch.value)") form(tags.input(type="test", name="branch", placeholder=branches[0], size="40")) form(tags.input(type="submit", value="View")) if (yield authz.actionAllowed('forceAllBuilds', req)): # XXX: Unsafe interpolation form(tags.button( type="button", onclick="forceBranch(branch.value || %r, %r)" % (branches[0], self.categories,) )("Force")) tag(form) table = tags.table(style="clear:both") tag(table) for bn in filter(lambda bn: bn not in self.failing_builders, builders): table(self.builder_row(bn, req, branches, num_builds)) table(tags.tr()(tags.td(colspan="100")( tags.h3(style="float:left; margin-top:0") ("Expected failures: ")))) for bn in filter(lambda bn: bn in self.failing_builders, builders): table(self.builder_row(bn, req, branches, num_builds)) defer.returnValue((yield flattenString(req, tag)))
def asTags(self): # type: () -> Iterable[Tag] """ Convert this L{Field} into some stuff that can be rendered in a L{twisted.web.template}. @return: A new set of tags to include in a template. @rtype: iterable of L{twisted.web.template.Tag} """ value = self.value if value is None: value = "" # type: ignore[unreachable] input_tag = tags.input(type=self.formInputType, name=self.formFieldName, value=value) error_tags = [] if self.error: error_tags.append( tags.div(class_="klein-form-validation-error")( self.error.message)) if self.formLabel: yield tags.label(self.formLabel, ": ", input_tag, *error_tags) else: yield input_tag yield error_tags
def overwrite_form(self, req, tag): node = self.original root = self.get_root(req) action = "%s/uri/%s" % (root, urllib.quote(node.get_uri())) done_url = "%s/uri/%s?t=info" % (root, urllib.quote(node.get_uri())) overwrite = T.form(action=action, method="post", enctype="multipart/form-data")( T.fieldset( T.input(type="hidden", name="t", value="upload"), T.input(type='hidden', name='when_done', value=done_url), T.legend("Overwrite", class_="freeform-form-label"), "Upload new contents: ", T.input(type="file", name="file"), " ", T.input(type="submit", value="Replace Contents") )) return tag(overwrite)
def check_form(self, req, tag): node = self.original quoted_uri = urlquote(node.get_uri()) target = self.get_root(req) + "/uri/" + quoted_uri if IDirectoryNode.providedBy(node): target += "/" check = T.form(action=target, method="post", enctype="multipart/form-data")(T.fieldset( T.input(type="hidden", name="t", value="check"), T.input(type="hidden", name="return_to", value="."), T.legend("Check on this object", class_="freeform-form-label"), T.div( "Verify every bit? (EXPENSIVE):", T.input(type="checkbox", name="verify"), ), T.div("Repair any problems?: ", T.input(type="checkbox", name="repair")), T.div("Add/renew lease on all shares?: ", T.input(type="checkbox", name="add-lease")), T.div( "Emit results in JSON format?: ", T.input(type="checkbox", name="output", value="JSON")), T.input(type="submit", value="Check"), )) return tag(check)
def render_POST(self, request): request.setHeader('content-type', 'text/html; charset=utf-8') app = self.getApplication(request) password = app.config.generate_for_site( request.args['username'][0], request.args['password'][0], request.args['site'][0]) element = tags.html( htmlHead, tags.body(tags.div( tags.input( size='1', value=password, onFocus=selectJS, onMouseUp='return false', ), ), class_='center'), ), return renderElement(request, element)
def reload(self, req, tag): if self.monitor.is_finished(): return "" # 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(T.input(type="submit", value="Cancel"), action=cancel_target, method="POST", enctype="multipart/form-data",) return (T.h2("Operation still running: ", T.a("Reload", href=reload_target), ), cancel_button,)
def deep_check_form(self, req, tag): ophandle = base32.b2a(os.urandom(16)) deep_check = T.form( action=req.path, method="post", enctype="multipart/form-data")(T.fieldset( T.input(type="hidden", name="t", value="start-deep-check"), T.input(type="hidden", name="return_to", value="."), T.legend("Run a deep-check operation (EXPENSIVE)", class_="freeform-form-label"), T.div( "Verify every bit? (EVEN MORE EXPENSIVE):", T.input(type="checkbox", name="verify"), ), T.div("Repair any problems?: ", T.input(type="checkbox", name="repair")), T.div("Add/renew lease on all shares?: ", T.input(type="checkbox", name="add-lease")), T.div("Emit results in JSON format?: ", T.input(type="checkbox", name="output", value="JSON")), T.input(type="hidden", name="ophandle", value=ophandle), T.input(type="submit", value="Deep-Check"), )) return tag(deep_check)
def body(self, req): status = self.getStatus(req) authz = self.getAuthz(req) builders = req.args.get( "builder", status.getBuilderNames(categories=self.categories)) branches = [b for b in req.args.get("branch", []) if b] if not branches: branches = ["trunk"] if branches and "trunk" not in branches: defaultCount = "1" else: defaultCount = "10" num_builds = int(req.args.get("num_builds", [defaultCount])[0]) tag = tags.div() tag(tags.script(src="txbuildbot.js")) tag( tags.h2(style="float:left; margin-top:0")("Latest builds: ", ", ".join(branches))) form = tags.form(method="get", action="", style="float:right", onsubmit="return checkBranch(branch.value)") form( tags.input(type="test", name="branch", placeholder=branches[0], size="40")) form(tags.input(type="submit", value="View")) if (yield authz.actionAllowed('forceAllBuilds', req)): # XXX: Unsafe interpolation form( tags.button(type="button", onclick="forceBranch(branch.value || %r, %r)" % ( branches[0], self.categories, ))("Force")) tag(form) table = tags.table(style="clear:both") tag(table) for bn in builders: builder = status.getBuilder(bn) state = builder.getState()[0] if state == 'building': state = 'idle' row = tags.tr() table(row) builderLink = path_to_builder(req, builder) row( tags.td(class_="box %s" % (state, ))( tags.a(href=builderLink)(bn))) builds = sorted([ build for build in builder.getCurrentBuilds() if build.getSourceStamp().branch in map_branches(branches) ], key=lambda build: build.getNumber(), reverse=True) builds.extend( builder.generateFinishedBuilds(map_branches(branches), num_builds=num_builds)) if builds: for b in builds: url = path_to_build(req, b) try: label = b.getProperty("got_revision") except KeyError: label = None # Label should never be "None", but sometimes # buildbot has disgusting bugs. if not label or label == "None" or len(str(label)) > 20: label = "#%d" % b.getNumber() if b.isFinished(): text = b.getText() else: when = b.getETA() if when: text = [ "%s" % (formatInterval(when), ), "%s" % (time.strftime( "%H:%M:%S", time.localtime(time.time() + when)), ) ] else: text = [] row( tags.td( align="center", bgcolor=_backgroundColors[b.getResults()], class_=("LastBuild box ", build_get_class(b)))([ (element, tags.br) for element in [tags.a(href=url)(label)] + text ])) else: row(tags.td(class_="LastBuild box")("no build")) defer.returnValue((yield flattenString(req, tag)))
def body(self, req): status = self.getStatus(req) authz = self.getAuthz(req) builders = req.args.get("builder", status.getBuilderNames(categories=self.categories)) branches = [b for b in req.args.get("branch", []) if b] if not branches: branches = ["trunk"] if branches and "trunk" not in branches: defaultCount = "1" else: defaultCount = "10" num_builds = int(req.args.get("num_builds", [defaultCount])[0]) tag = tags.div() tag(tags.script(src="txbuildbot.js")) tag(tags.h2(style="float:left; margin-top:0")("Latest builds: ", ", ".join(branches))) form = tags.form(method="get", action="", style="float:right", onsubmit="return checkBranch(branch.value)") form(tags.input(type="test", name="branch", placeholder=branches[0], size="40")) form(tags.input(type="submit", value="View")) if (yield authz.actionAllowed('forceAllBuilds', req)): # XXX: Unsafe interpolation form(tags.button(type="button", onclick="forceBranch(branch.value || %r, %r)" % (branches[0], self.categories,) )("Force")) tag(form) table = tags.table(style="clear:both") tag(table) for bn in builders: builder = status.getBuilder(bn) state = builder.getState()[0] if state == 'building': state = 'idle' row = tags.tr() table(row) builderLink = path_to_builder(req, builder) row(tags.td(class_="box %s" % (state,))(tags.a(href=builderLink)(bn))) builds = sorted([ build for build in builder.getCurrentBuilds() if build.getSourceStamps()[0].branch in map_branches(branches) ], key=lambda build: build.getNumber(), reverse=True) builds.extend(builder.generateFinishedBuilds(map_branches(branches), num_builds=num_builds)) if builds: for b in builds: url = path_to_build(req, b) try: label = b.getProperty("got_revision") except KeyError: label = None # Label should never be "None", but sometimes # buildbot has disgusting bugs. if not label or label == "None" or len(str(label)) > 20: label = "#%d" % b.getNumber() if b.isFinished(): text = b.getText() else: when = b.getETA() if when: text = [ "%s" % (formatInterval(when),), "%s" % (time.strftime("%H:%M:%S", time.localtime(time.time() + when)),) ] else: text = [] row(tags.td( align="center", bgcolor=_backgroundColors[b.getResults()], class_=("LastBuild box ", build_get_class(b)))([ (element, tags.br) for element in [tags.a(href=url)(label)] + text]) ) else: row(tags.td(class_="LastBuild box")("no build")) defer.returnValue((yield flattenString(req, tag)))