def content(self, name, **kwargs): game = games[name] yield t.h1["Game: ", name] yield t.h2["Min. Date: ", str(game.mindate)] yield t.h2["Players"] header = t.tr[t.th["Name"], t.th["Date"], t.th["Cem'y"], t.th, [] if game.locked else t.th] rows = [ t.form(method='GET', action='/part')[ t.tr[t.td[t.a(href="/player" + self.query_string(game=name, name=n))[n]], t.td[str(game.players[n].date)], t.td(Class='num')[str(game.players[n].kia)], t.td['Leader' if game.players[n].leader else []], [] if game.locked else t.td[ t.input(type='hidden', name='game', value=name), t.input(type='hidden', name='name', value=n), t.input(type='submit', value='Remove')], ]] for n in sorted(game.players) ] rows.append( t.form(method='GET', action='/join') [t.input(type='hidden', name='game', value=name), t.tr[t.td[t.input(type='text', name='name')], t.td(colspan=2), [] if game.locked else t. td[t.input(type='submit', value='New')]]]) if not game.locked: yield t.form(method='GET', action='/lock')[ t.input(type='hidden', name='game', value=name), t.input(type='submit', value='Lock')] yield t.table[header, rows] def shortresult(contract): front = [ p for p in contract.date if contract.date[p] == contract.firstdate ] text = [ '%s, %s, %s' % (p.name, contract.date[p], contract.first(p)) for p in front ] return '(%s)' % ('; '.join(text)) yield t.h2["Contracts"] yield t.ul[[ t.li[t.a(href="/result" + self.query_string(game=name, contract=n))[n], ': ', shortresult(game.contracts[n])] for n in sorted(game.contracts, key=lambda n: game.contracts[n].firstdate) ]]
def render_forms(self, ctx, data): forms = [] if self.node.is_readonly(): return T.div["No upload forms: directory is read-only"] if self.dirnode_children is None: return T.div["No upload forms: directory is unreadable"] mkdir = T.form(action=".", method="post", enctype="multipart/form-data")[ T.fieldset[ T.input(type="hidden", name="t", value="mkdir"), T.input(type="hidden", name="when_done", value="."), T.legend(class_="freeform-form-label")["Create a new directory in this directory"], "New directory name: ", T.input(type="text", name="name"), " ", T.input(type="submit", value="Create"), ]] forms.append(T.div(class_="freeform-form")[mkdir]) upload = T.form(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="."), T.legend(class_="freeform-form-label")["Upload a file to this directory"], "Choose a file to upload: ", T.input(type="file", name="file", class_="freeform-input-file"), " ", T.input(type="submit", value="Upload"), " Mutable?:", T.input(type="checkbox", name="mutable"), ]] forms.append(T.div(class_="freeform-form")[upload]) mount = T.form(action=".", method="post", enctype="multipart/form-data")[ T.fieldset[ T.input(type="hidden", name="t", value="uri"), T.input(type="hidden", name="when_done", value="."), T.legend(class_="freeform-form-label")["Add a link to a file or directory which is already in Tahoe-LAFS."], "New child name: ", T.input(type="text", name="name"), " ", "URI of new child: ", T.input(type="text", name="uri"), " ", T.input(type="submit", value="Attach"), ]] forms.append(T.div(class_="freeform-form")[mount]) return forms
def render_maybeEdit(self, ctx, _): """Render action buttons if available.""" # pylint: disable-msg=E1101 if manages_list(ctx, must_user(ctx), self.list): srv = IService(ctx) if srv.isReserved(self.item): notify = T.p[T.input( type="checkbox", name="notify", value="1", checked=""), u"\xa0Avertir la personne qui l'a réservé"] else: notify = [] return ctx.tag(_class="editable bl")[T.div(_class="br")[T.div( _class="tl")[T.div(_class="tr")[T.form( name='confirm', action=url.here.child('confirm'), method='POST', _class="edcontent")[ notify, T.input(type='submit', name='confirm', value=u"Confirmer l'effacement"), T.input(type='submit', name='cancel', value=u"Annuler" ), ]]]]] else: return ''
def calculateDefaultSkin(self, context): if self.isGrouped: frm = tags.invisible butt = "" fld = tags.invisible else: frm = tags.form( id=slot("form-id"), name=slot("form-id"), action=slot("form-action"), method="post", enctype="multipart/form-data", **{"accept-charset": "utf-8"} ) butt = slot("form-button") fld = tags.fieldset[tags.input(type="hidden", name="_charset_")] ## Provide default skin since no skin was provided for us. context.tag.clear()[ frm[ fld[ tags.legend(_class="freeform-form-label")[slot("form-label")], tags.div(_class="freeform-form-description")[slot("form-description")], tags.div(_class="freeform-form-error")[slot("form-error")], slot("form-arguments"), butt, ] ] ]
def render_check_form(self, ctx, data): node = self.original quoted_uri = urllib.quote(node.get_uri()) target = self.get_root(ctx) + "/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(class_="freeform-form-label")["Check on this object"], 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 ctx.tag[check]
def rend(self, context, data): context.remember(data, iformless.IBinding) from formless import configurable as conf configurable = conf.GroupConfigurable(data.boundTo, data.typedValue.iface) context.remember(configurable, iformless.IConfigurable) bindingNames = configurable.getBindingNames(context) def generateBindings(): for name in bindingNames: bnd = configurable.getBinding(context, name) renderer = iformless.IBindingRenderer(bnd, defaultBindingRenderer) renderer.isGrouped = True renderer.needsSkin = True yield tags.invisible(data=bnd, render=renderer, key=name) return getError(context), tags.form( id=keyToXMLID(context.key), enctype="multipart/form-data", action=calculatePostURL(context, data), method="post", **{'accept-charset': 'utf-8' })[tags.fieldset[tags.legend( _class="freeform-form-label")[data.label], tags.input(type='hidden', name='_charset_'), generateBindings(), tags.input(type="submit")]]
def render_controls(self, ctx, data): request = inevow.IRequest(ctx) if request.args.get('shutdown'): return "" return T.form(method="POST")[T.input(type="submit", name="shutdown", value="Shut Down")]
def render_exits(self, ctx, data): if self.bse != 'Room': return '' xs = self.obj.exits() xs.sort(key=attrgetter('name')) if xs: lines = [T.h2(_class="section")['Exits:']] rows = [] for x in xs: tzid = x.tzid destf = 'dest_%s' % tzid namef = 'name_%s' % tzid dest = x.destination rows.append(T.tr[ T.td[self.deletelink_widget(x)], T.td[self.editlink_widget(x)], T.td[self.str_widget(namef, x.name, 20)], T.td['-->'], T.td[self.rooms_widget(destf, dest)], T.td[self.editlink_widget(dest)], T.td[T.input(_type="submit", value="update")]]) tbl = T.table(_class="center")[rows] lines.append(tbl) return T.form(action="/exits/update/", method="POST")[lines] else: return T.h2(_class="warn")['No exits']
def page_body(kwargs): merits = parse_merits(kwargs) checks = [gen_checks(b, merits) for b in ribbonator.bodies] job = '?' + '&'.join('='.join(gen_job(b, merits[b])) for b in merits if 'soi' in merits[b]) print('serving index', job) return [ t.script(type='text/javascript')[PAGE_SCRIPT], t.h1['RSS Ribbonator - Clumsy Web Interface'], t. p["Generator and RSS Ribbons by Edward Cree. Based on the KSP Ribbons by Unistrut. 'Inspired' by ", t.a(href='http://www.kerbaltek.com/ribbons' )["Ezriilc's Ribbon Generator"], "."], t.p[t.a(href="https://github.com/ec429/ribbonator")["Source Code"]], t. p["Select your achievements with the checkboxes and radiobuttons, and click Submit to generate the ribbon image URL. This will also generate a Ribbonator 'job card' URL; bookmark this if you want to be able to update your ribbons later."], t. p["Moons will only appear when their parent planet's 'Reached SOI' is selected."], t. p["The Ribbonator does not store any user data. Instead, the ribbon contents are encoded in the URL of the image, using the same 'job card' format."], t. p["I recommend against linking directly to the generated image. Download it, then upload to some other hosting; that way your image won't break if the Ribbonator moves, dies, or has bandwidth troubles."], t.img(src='gen.png' + job, alt="Generated ribbons"), t.p[t.a( href=job)["Job Card URL - bookmark this"] if len(job) > 1 else ''], t.form(method='GET')[t.ul[checks], t.input(type='submit', value='Submit')], ]
class Page(ManualFormMixin, rend.Page): addSlash = True docFactory = loaders.stan( t.html[ t.head[ t.title['Advanced Manualform'] ], t.body[ t.p['Use the form to find out how to easily and manually handle them'], t.form(action=url.here.child('_submit!!post'), enctype="multipart/form-data", method='post' )[ t.input(type='text', name='what'), # the name attribute must be present and must be # post_btn for all the buttons in the form t.input(type='submit', value='btn1', name=BUTTON), t.input(type='submit', value='btn2', name=BUTTON) ] ] ] ) def form_post_btn1(self, what=None): # 'what' is a keyword argument, and must be the same name that you # give to the widget. print "btn1:", what def form_post_btn2(self, what=None): # see above for 'what'. print "btn2:", what
class StatusWidget(athena.LiveElement): jsClass = u'ControllerModule.StatusWidget' docFactory = loaders.stan( tags.div(render=tags.directive('liveElement'))[tags.div( id="statusWidget" )[tags.form(id="statusidform", action="""javascript: var statusidform = document.getElementById('statusidform'); var w = Nevow.Athena.Widget.get(statusidform); w.refreshStatus(); """) [tags.input(id="statusidfield", type="text"), tags.br, tags.input(type="checkbox", id="pending", checked="true", onChange="this.form.submit()")["pending"], tags.input(type="checkbox", id="queue", checked="true", onChange="this.form.submit()")["queue"], tags. input(type="checkbox", id="history", onChange="this.form.submit()" )["history"], tags. input(type="checkbox", id="locals", onChange="this.form.submit()" )["locals"], tags.br, tags.input(type="submit", value="refresh status")], tags.div(id="statusOut")]]) def __init__(self, controller): self.controller = controller reactor.callLater(.1, self.callRemote, 'getIDs') def status(self, targets, pending=True, queue=True, history=True, locals=True): args = (pending, queue, history, locals) idlist = parseTargets(targets) if idlist is False: return self.fail() d = self.controller.status(idlist) return d.addCallbacks(self.statusOK, self.fail, callbackArgs=args) athena.expose(status) def statusOK(self, resultList, *args): return self.finish(statusListToHTML(resultList, *args)) def refreshStatus(self, *args): return self.callRemote('refreshStatus') def finish(self, s): return self.callRemote('updateStatus', unicode(s)) def fail(self, f=None): return self.finish('Failure')
def render_mkdir_form(self, ctx, data): # This is a form where users can create new directories. # Users can choose SDMF or MDMF from a radio button. mkdir_sdmf = T.input(type='radio', name='format', value='sdmf', id='mkdir-sdmf', checked='checked') mkdir_mdmf = T.input(type='radio', name='format', value='mdmf', id='mkdir-mdmf') form = T.form( action="uri", method="post", enctype="multipart/form-data" )[T.fieldset[ T.legend(class_="freeform-form-label")["Create a directory"], mkdir_sdmf, T.label(for_='mkdir-sdmf')[" SDMF"], SPACE, mkdir_mdmf, T.label(for_='mkdir-mdmf')[" MDMF (experimental)"], SPACE * 2, T.input(type="hidden", name="t", value="mkdir"), T.input(type="hidden", name="redirect_to_result", value="true"), T.input(type="submit", value="Create a directory"), ]] return T.div[form]
def render_upload_form(self, ctx, data): # This is a form where users can upload unlinked files. # Users can choose immutable, SDMF, or MDMF from a radio button. upload_chk = T.input(type='radio', name='format', value='chk', id='upload-chk', checked='checked') upload_sdmf = T.input(type='radio', name='format', value='sdmf', id='upload-sdmf') upload_mdmf = T.input(type='radio', name='format', value='mdmf', id='upload-mdmf') form = T.form( action="uri", method="post", enctype="multipart/form-data" )[T.fieldset[T.legend( class_="freeform-form-label")["Upload a file"], T.div[ "Choose a file:" + SPACE, T.input(type="file", name="file", class_="freeform-input-file" )], T.input(type="hidden", name="t", value="upload"), T.div[upload_chk, T.label(for_="upload-chk")[" Immutable"], SPACE, upload_sdmf, T.label(for_="upload-sdmf")[" SDMF"], SPACE, upload_mdmf, T.label(for_="upload-mdmf")[" MDMF (experimental)"], SPACE * 2, T.input(type="submit", value="Upload!")], ]] return T.div[form]
def render_upload_form(self, ctx, data): # This is a form where users can upload unlinked files. # Users can choose immutable, SDMF, or MDMF from a radio button. upload_chk = T.input(type='radio', name='format', value='chk', id='upload-chk', checked='checked') upload_sdmf = T.input(type='radio', name='format', value='sdmf', id='upload-sdmf') upload_mdmf = T.input(type='radio', name='format', value='mdmf', id='upload-mdmf') form = T.form(action="uri", method="post", enctype="multipart/form-data")[ T.fieldset[ T.legend(class_="freeform-form-label")["Upload a file"], T.div["Choose a file:"+SPACE, T.input(type="file", name="file", class_="freeform-input-file")], T.input(type="hidden", name="t", value="upload"), T.div[upload_chk, T.label(for_="upload-chk") [" Immutable"], SPACE, upload_sdmf, T.label(for_="upload-sdmf")[" SDMF"], SPACE, upload_mdmf, T.label(for_="upload-mdmf")[" MDMF (experimental)"], SPACE*2, T.input(type="submit", value="Upload!")], ]] return T.div[form]
def render_childDel(self, context, xxx_todo_changeme): (name, _) = xxx_todo_changeme ret = T.form(action="./freeform_post!!deleteChild", enctype="multipart/form-data", method="POST")[ T.input(type="hidden", name="name", value=name), T.input(type="submit", value="Delete")] return ret
def rend(self, context, data): context.remember(data, iformless.IBinding) from formless import configurable as conf configurable = conf.GroupConfigurable(data.boundTo, data.typedValue.iface) context.remember(configurable, iformless.IConfigurable) bindingNames = configurable.getBindingNames(context) def generateBindings(): for name in bindingNames: bnd = configurable.getBinding(context, name) renderer = iformless.IBindingRenderer(bnd, defaultBindingRenderer) renderer.isGrouped = True renderer.needsSkin = True yield tags.invisible( data=bnd, render=renderer, key=name) return getError(context), tags.form( id=keyToXMLID(context.key), enctype="multipart/form-data", action=calculatePostURL(context, data), method="post", **{'accept-charset':'utf-8'})[ tags.fieldset[ tags.legend(_class="freeform-form-label")[data.label], tags.input(type='hidden', name='_charset_'), generateBindings(), tags.input(type="submit")]]
def render_controls(self, ctx, data): request = inevow.IRequest(ctx) if request.args.get('shutdown'): return "" return tags.form(method="POST")[ tags.input(type="submit", name="shutdown", value="Shut Down") ]
def render_settings(self, ctx, data): settings = self.obj.settings[:] if self.bse != 'Room': settings.append('room') if self.bse == 'Exit': settings.append('destination') lines = [] for setting in settings: error = self.args.get('_%s__error' % setting, False) if error: cls = 'textlabel_error' else: cls = 'textlabel' label = T.td(_class=cls)[setting] val = self.obj.setting(setting) if val is None: val = getattr(self.obj, setting, None) inpt = T.td[self.get_setting_widget(setting, val)] lines.append(T.tr[label, inpt]) if self.bse != 'Room' and self.obj.container != self.obj.room: label = T.td(_class="textlabel")['container'] inpt = T.td[self.container_widget(self.obj)] lines.append(T.tr[label, inpt]) empty = T.td(_class='empty')[''] lines.append(T.tr[empty, empty]) submit = T.input(_type="submit", value=" Change ") lines.append(T.tr[empty, T.td[submit]]) tbl = T.table(_class="center")[lines] return T.form(action=".", method="POST")[tbl]
def __init__(self, ctx, restWriter, key, srcId): self.restWriter = restWriter form = iformal.IForm(ctx) u = widgetResourceURLFromContext( ctx, form.name).child(key).child(srcId).child('_submit') self.destId = srcId + '-dest' formId = srcId + '-form' stan = T.html( )[T.head()[T.script(type="text/javascript")[""" function ReSTTranslate() { dest = document.getElementById('%(destId)s'); form = document.getElementById('%(formId)s'); src = parent.document.getElementById('%(srcId)s'); dest.value = src.value; form.submit(); } """ % { 'srcId': srcId, 'destId': self.destId, 'formId': formId }]], T.body( )[T.form(id=formId, method="POST", action=u )[T.input(type="hidden", name=self.destId, id=self.destId)], T.script(type="text/javascript")["ReSTTranslate();"], ], ] self.docFactory = loaders.stan(stan)
def __init__(self, ctx, restWriter, key, srcId): self.restWriter = restWriter form = iformal.IForm( ctx ) u = formal_widgetResourceURLFromContext(ctx, form.name).child(key).child( srcId ).child('_submit') self.destId=srcId + '-dest' formId=srcId + '-form' stan = T.html()[ T.head()[ T.script(type="text/javascript")[""" function ReSTTranslate() { dest = document.getElementById('%(destId)s'); form = document.getElementById('%(formId)s'); src = parent.document.getElementById('%(srcId)s'); dest.value = src.value; form.submit(); } """%{'srcId':srcId, 'destId':self.destId, 'formId':formId}] ], T.body()[ T.form(id=formId, method="POST", action=u)[ T.input(type="hidden", name=self.destId, id=self.destId) ], T.script(type="text/javascript")["ReSTTranslate();"], ], ] self.docFactory = loaders.stan(stan)
def render_forms(self, ctx, data): forms = [] if self.node.is_readonly(): return T.div["No upload forms: directory is read-only"] if self.dirnode_children is None: return T.div["No upload forms: directory is unreadable"] mkdir = T.form( action=".", method="post", enctype="multipart/form-data")[T.fieldset[ T.input(type="hidden", name="t", value="mkdir"), T.input(type="hidden", name="when_done", value="."), T.legend(class_="freeform-form-label" )["Create a new directory in this directory"], "New directory name: ", T.input(type="text", name="name"), " ", T.input(type="submit", value="Create"), ]] forms.append(T.div(class_="freeform-form")[mkdir]) upload = T.form( 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="."), T.legend(class_="freeform-form-label" )["Upload a file to this directory"], "Choose a file to upload: ", T.input(type="file", name="file", class_="freeform-input-file" ), " ", T.input(type="submit", value="Upload"), " Mutable?:", T.input(type="checkbox", name="mutable"), ]] forms.append(T.div(class_="freeform-form")[upload]) mount = T.form( action=".", method="post", enctype="multipart/form-data" )[T.fieldset[ T.input(type="hidden", name="t", value="uri"), T.input(type="hidden", name="when_done", value="."), T.legend(class_="freeform-form-label") ["Add a link to a file or directory which is already in Tahoe-LAFS."], "New child name: ", T.input(type="text", name="name"), " ", "URI of new child: ", T.input(type="text", name="uri"), " ", T.input(type="submit", value="Attach"), ]] forms.append(T.div(class_="freeform-form")[mount]) return forms
def render_possibleActions(self, ctx, data): """Render the buttons under am item.""" # pylint: disable-msg=E1101 avatar = maybe_user(ctx) if manages_list(ctx, avatar, self.list): child = url.here.child(str(data.key)) modify = T.div(_class="listaction")[ u'» ', T.a(href=child)[u'Modifier'], ' :: ', T.a(href=child.child('delete'))[u'Effacer']] else: if not data.res: # the object is not yet reserved, so it can be for us k = str(data.key) modify = T.form(action=url.here.child(k).child('get'), id='item-' + k, _class='item-op', method='POST')[T.input( type='submit', name='get', value=u'Réserver cette idée')] else: if avatar.anonymous: user = None else: user = avatar.user.id if data.res[0] == user: k = str(data.key) donated = T.a(href=url.here.child(k).child('donated'), style="margin-left:2em" )[u"»\xa0Vous avez donné le cadeau\xa0?"] modify = T.form( action=url.here.child(k).child('giveup'), id='item-' + k, _class='item-op', method='POST')[T.input(type='submit', name='giveup', value=u'Abandonner cette idée'), donated] else: modify = '' return ctx.tag[modify]
def content(self, **kwargs): yield t.h1["KSP Race Into Space server"] yield t.h2["Games in progress"] header = t.tr[t.th["Name"], t.th["Players"], t.th["Min. Date"]] rows = [t.form(method='GET', action='/rmgame')[t.tr[ t.td[t.a(href="/game" + self.query_string(name=n))[n]], t.td[", ".join(games[n].players.keys())], t.td[str(games[n].mindate)], t.td if games[n].locked or not kwargs.get('_local') else t.td[t.input(type='hidden', name='game', value=n), t.input(type='submit', value='End')] ]] for n in sorted(games)] rows.append(t.form(method='GET', action='/newgame')[t.tr[ t.td[t.input(type='text', name='name')], t.td(colspan=2), t.td[t.input(type='submit', value='New')]]]) yield t.table[header, rows]
def render_incident_button(self, ctx, data): # this button triggers a foolscap-logging "incident" form = T.form( action="report_incident", method="post", enctype="multipart/form-data")[T.fieldset[ T.input(type="hidden", name="t", value="report-incident"), "What went wrong?" + SPACE, T.input(type="text", name="details"), SPACE, T.input(type="submit", value=u"Save \u00BB"), ]] return T.div[form]
def render_incident_button(self, ctx, data): # this button triggers a foolscap-logging "incident" form = T.form(action="report_incident", method="post", enctype="multipart/form-data")[ T.fieldset[ T.input(type="hidden", name="t", value="report-incident"), "What went wrong?"+SPACE, T.input(type="text", name="details"), SPACE, T.input(type="submit", value=u"Save \u00BB"), ]] return T.div[form]
def render_mkdir_form(self, ctx, data): # this is a form where users can create new directories form = T.form(action="uri", method="post", enctype="multipart/form-data")[ T.fieldset[ T.legend(class_="freeform-form-label")["Create a directory"], T.input(type="hidden", name="t", value="mkdir"), T.input(type="hidden", name="redirect_to_result", value="true"), T.input(type="submit", value="Create a directory"), ]] return T.div[form]
def render_deep_stats_form(self, ctx, data): ophandle = base32.b2a(os.urandom(16)) deep_stats = T.form(action=".", method="post", enctype="multipart/form-data")[ T.fieldset[ T.input(type="hidden", name="t", value="start-deep-stats"), T.legend(class_="freeform-form-label")["Run a deep-stats operation (EXPENSIVE)"], T.input(type="hidden", name="ophandle", value=ophandle), T.input(type="submit", value="Deep-Stats"), ]] return ctx.tag[deep_stats]
def render_repair(self, ctx, data): if data.is_healthy(): return "" repair = T.form( action=".", method="post", enctype="multipart/form-data")[ T.fieldset[T.input(type="hidden", name="t", value="check"), T.input(type="hidden", name="repair", value="true"), T.input(type="submit", value="Repair"), ]] return "" # repair button disabled until we make it work correctly, # see #622 for details return ctx.tag[repair]
def render_view_form(self, ctx, data): # this is a form where users can download files by URI, or jump to a # named directory form = T.form( action="uri", method="get", enctype="multipart/form-data")[ T.fieldset[T.legend( class_="freeform-form-label")["View a file or directory"], "Tahoe-URI to view:" + SPACE, T.input(type="text", name="uri"), SPACE * 2, T.input(type="submit", value="View!"), ]] return T.div[form]
def render_forms(self, ctx, data): f = T.form(action=".", method="get") table = [] for (name,default_value,argtype,description) in self.DEFAULT_PARAMETERS: old_value = self.parameters[name] i = self.make_input(name, old_value) table.append(T.tr[T.td[name+":"], T.td[i], T.td[description]]) go = T.input(type="submit", value="Recompute") return [T.h2["Simulation Parameters:"], f[T.table[table], go], ]
def render_deep_stats_form(self, ctx, data): ophandle = base32.b2a(os.urandom(16)) deep_stats = T.form( action=".", method="post", enctype="multipart/form-data")[T.fieldset[ T.input(type="hidden", name="t", value="start-deep-stats"), T.legend(class_="freeform-form-label" )["Run a deep-stats operation (EXPENSIVE)"], T.input(type="hidden", name="ophandle", value=ophandle), T.input(type="submit", value="Deep-Stats"), ]] return ctx.tag[deep_stats]
class NotLoggedIn(rend.Page): """The resource that is returned when you are not logged in""" addSlash = True docFactory = loaders.stan(tags.html[ tags.head[tags.title["Not Logged In"]], tags.body[tags.form(action=guard.LOGIN_AVATAR, method='post')[ tags.table[ tags.tr[tags.td["Username:"******"Password:"], tags. td[tags.input(type='password', name='password')], ]], tags.input(type='submit'), tags.p, ]]])
def render_incident_button(self, ctx, data): # this button triggers a foolscap-logging "incident" form = T.form(action="report_incident", method="post", enctype="multipart/form-data")[ T.fieldset[ T.legend(class_="freeform-form-label")["Report an Incident"], T.input(type="hidden", name="t", value="report-incident"), "What went wrong?: ", T.input(type="text", name="details"), " ", T.input(type="submit", value="Report!"), ]] return T.div[form]
def getWidgetDocument(self): # XXX No support for rendering these yet! f = liveform.LiveForm( self.submit, [liveform.Parameter('argument', None, unicode)]) f.docFactory = loaders.stan(tags.form(render=tags.directive('liveElement'))[ tags.select(name="argument")[ tags.option(value="apples")["apples"], tags.option(value="oranges")["oranges"]], tags.input(type='submit', render=tags.directive('submitbutton'))]) f.setFragmentParent(self) return f
def createWorldPayForm(ctx, config, purchaseId, basketHash, totalPrice, description, cardholder, withDelivery=False, fixContact=False): def maxLength(src, length): return src[:length] # Check the purchase ID is not too long purchaseId = str(purchaseId) if purchaseId != maxLength(purchaseId, 255): raise Exception("purchaseId must be less than 255 characters") # Decode the test mode. testMode = config['testMode'] if testMode is not None: if testMode.lower() == 'succeed': testMode = ALWAYS_SUCCEED else: testMode = ALWAYS_FAIL # Decide what callback URL to use, if any. callback = callbackURL(ctx, config.get('callback')) rv = T.form(action=config['url'], method="post") # Worldpay account access rv[T.input(type="hidden", name="instId", value=config["instid"])] if testMode is not None: rv[T.input(type="hidden", name="testMode", value=testMode)] # General basket stuff rv[T.input(type="hidden", name="cartId", value=purchaseId)] rv[T.input(type="hidden", name="amount", value="%0.2f"%totalPrice)] rv[T.input(type="hidden", name="currency", value="GBP")] rv[T.input(type="hidden", name="desc", value=description)] # Basket hash rv[T.input(type="hidden", name="M_hash", value=basketHash)] # Buyer's details rv[T.input(type="hidden", name="name", value=maxLength(cardholder.name, 40))] rv[T.input(type="hidden", name="address", value=maxLength(cardholder.address, 255))] rv[T.input(type="hidden", name="postcode", value=maxLength(cardholder.postcode, 12))] rv[T.input(type="hidden", name="country", value=cardholder.country)] rv[T.input(type="hidden", name="email", value=maxLength(cardholder.email,80))] # Enable entry of the delivery address if withDelivery: rv[T.input(type="hidden", name="withDelivery")] # The cardholder and delivery details can optionally be fixed. if fixContact: rv[T.input(type="hidden", name="fixContact")] # Callback override if callback is not None: rv[T.input(type="hidden", name="MC_callback", value=callback)] # A button to post the form to Worldpay rv[T.input(type="submit", value="Enter Payment Details")] return rv
def render_view_form(self, ctx, data): # this is a form where users can download files by URI, or jump to a # named directory form = T.form(action="uri", method="get", enctype="multipart/form-data")[ T.fieldset[ T.legend(class_="freeform-form-label")["View a file or directory"], "Tahoe-URI to view: ", T.input(type="text", name="uri"), " ", T.input(type="submit", value="View!"), ]] return T.div[form]
def render_download_form(self, ctx, data): # this is a form where users can download files by URI form = T.form( action="uri", method="get", enctype="multipart/form-data")[T.fieldset[ T.legend(class_="freeform-form-label")["Download a file"], T.div["Tahoe-URI to download:" + SPACE, T.input(type="text", name="uri")], T.div["Filename to download as:" + SPACE, T.input(type="text", name="filename")], T.input(type="submit", value="Download!"), ]] return T.div[form]
def getWidgetDocument(self): # XXX No support for rendering these yet! f = liveform.LiveForm(self.submit, [liveform.Parameter('argument', None, unicode)]) f.docFactory = loaders.stan( tags.form(render=tags.directive('liveElement')) [tags.select( name="argument")[tags.option(value="apples")["apples"], tags.option(value="oranges")["oranges"]], tags.input(type='submit', render=tags.directive('submitbutton'))]) f.setFragmentParent(self) return f
def render_incident_button(self, ctx, data): # this button triggers a foolscap-logging "incident" form = T.form( action="report_incident", method="post", enctype="multipart/form-data")[T.fieldset[ T.legend(class_="freeform-form-label")["Report an Incident"], T.input(type="hidden", name="t", value="report-incident"), "What went wrong?:" + SPACE, T.input(type="text", name="details"), SPACE, T.input(type="submit", value="Report!"), ]] return T.div[form]
def render_repair(self, ctx, data): if data.is_healthy(): return "" repair = T.form(action=".", method="post", enctype="multipart/form-data")[ T.fieldset[ T.input(type="hidden", name="t", value="check"), T.input(type="hidden", name="repair", value="true"), T.input(type="submit", value="Repair"), ]] return "" # repair button disabled until we make it work correctly, # see #622 for details return ctx.tag[repair]
class OpenidLogin(rend.Page): form = lambda: T.form(method="post", action="") docFactory = loaders.stan([ form()["openid: ", T.input(name="openid"), T.input(type='submit', value='login')], form()[T.input(type='hidden', name='openid', value='https://www.google.com/accounts/o8/id'), T.input(type='submit', value='Use google account')], form()[T.input(type='hidden', name='openid', value='yahoo.com'), T.input(type='submit', value='Use yahoo account')], ])
def data_login_form(self, ctx, data): if(self.user): result = tags.p()[ "You have been successfully logged in as %s" % self.user.username ] else: result = tags.form(method="POST")[[ tags.p()['Enter your OpenID identifier to login:'], tags.label(_for="openid-field")["id:"], tags.input(type="text", size="60", name="identity"), tags.input(type="submit", name="submit", value="login"), ]] return result
def render_forms(self, ctx, data): f = T.form(action=".", method="get") table = [] for (name, default_value, argtype, description) in self.DEFAULT_PARAMETERS: old_value = self.parameters[name] i = self.make_input(name, old_value) table.append(T.tr[T.td[name + ":"], T.td[i], T.td[description]]) go = T.input(type="submit", value="Recompute") return [ T.h2["Simulation Parameters:"], f[T.table[table], go], ]
def line(queryName, label): ret = json.parse((yield getPage( "http://bigasterisk.com/magma/light/state?name=%s" % queryName, headers={'x-identity-forward': 'secret-8-' + self.identity}))) currently = ret['value'] returnValue( T.form(method="POST", action="light/state") [T.input(type="hidden", name="name", value=queryName), T.div[label, " ", T.span[currently], ", turn ", T.input(type="submit", name="value", value="off" if currently == 'on' else "on")]])
def render_upload_form(self, ctx, data): # this is a form where users can upload unlinked files form = T.form(action="uri", method="post", enctype="multipart/form-data")[ T.fieldset[ T.legend(class_="freeform-form-label")["Upload a file"], T.div["Choose a file: ", T.input(type="file", name="file", class_="freeform-input-file")], T.input(type="hidden", name="t", value="upload"), T.div[T.input(type="checkbox", name="mutable"), T.label(for_="mutable")["Create mutable file"], " ", T.input(type="submit", value="Upload!")], ]] return T.div[form]
def render_download_form(self, ctx, data): # this is a form where users can download files by URI form = T.form(action="uri", method="get", enctype="multipart/form-data")[ T.fieldset[ T.legend(class_="freeform-form-label")["Download a file"], T.div["Tahoe-URI to download: ", T.input(type="text", name="uri")], T.div["Filename to download as: ", T.input(type="text", name="filename")], T.input(type="submit", value="Download!"), ]] return T.div[form]
class TreeRenderer(rend.Page): implements(ITreeEdit) addSlash = True docFactory = loaders.htmlstr(""" <html> <head><title>Tree Editor</title></head> <body><h1><span nevow:data="description" nevow:render="string">Tree Description</span></h1> <span nevow:render="descriptionForm"/> <ol nevow:data="children" nevow:render="sequence"> <li nevow:pattern="item"><span nevow:render="childLink"/> <span nevow:render="childDel"/> </li> </ol> <a href="..">Up</a> </body> </html> """) def setDescription(self, description): self.original.description = description def addChild(self, name, description): self.original.add(Tree(name, description)) def deleteChild(self, name): del self.original[name] def data_description(self, context, data): return self.original.description def data_children(self, context, data): return self.original.items() def render_childLink(self, context, data): return T.a(href='subtree_%s/' % data[0])[data[1].description] def childFactory(self, ctx, name): if name.startswith('subtree_'): return self.original[name[len('subtree_'):]] def render_descriptionForm(self, context, data): return webform.renderForms() def render_childDel(self, context, (name, _)): ret = T.form( action="./freeform_post!!deleteChild", enctype="multipart/form-data", method="POST")[T.input(type="hidden", name="name", value=name), T.input(type="submit", value="Delete")] return ret
class ConfigurationWizard(rend.Page): __implements__ = IConfigurationWizard, rend.Page.__implements__ def render_configBody(self, ctx, data): return webform.renderForms(bindingNames=[ctx.arg('config_type')]) def render_result(self, ctx, data): result = inevow.IHand(ctx, default=None) if result is not None: return result return '' docFactory = loaders.stan(T.html[ T.head[ T.title["Configuration Wizard"], stylesheet], T.body[ T.span(render=render_result), T.h1["Add configuration"], render_configBody, T.form(action=".")[ T.input(type="submit", name="cancel", value="Cancel")]]]) def divmod(self, req, name, username, password): self.original.updateOptions(dict( username=username, email_address="*****@*****.**" % (username, ), register_uri='sip:divmod.com:5060', register_user=username, register_authuser=username, register_authpasswd=password)) self.pokeOptsFile(name) req.setComponent(iformless.IRedirectAfterPost, '/') def fwd(self, req, name, username, password): self.original.updateOptions(dict(username=username, email_address='*****@*****.**' % (username, ), outbound_proxy_url='sip:fwdnat.pulver.com:5082', register_uri='sip:fwd.pulver.com:5060', register_authuser=username, register_user=username, register_authpasswd=password)) self.pokeOptsFile(name) req.setComponent(iformless.IRedirectAfterPost, '/') def pokeOptsFile(self, name): self.original.saveOptsFile() self.original.loadOptsFile() self.original.setOptsFile('.shtoomrc.d/%s' % (name, )) self.original.saveOptsFile() self.original.setOptsFile('.shtoomrc') open(currentConfigFilename, 'w').write(name)
class MyPage(rend.Page): addSlash = True docFactory = loaders.stan( tags.html[ tags.head[tags.title["Hi Boy"]], tags.body[ tags.invisible(render=tags.directive("isLogged"))[ tags.div(pattern="False")[ tags.form(action=guard.LOGIN_AVATAR, method='post')[ tags.table[ tags.tr[ tags.td[ "Username:"******"Password:"******"True")[ tags.h3["Hi bro"], tags.invisible(render=tags.directive("sessionId")), tags.br, tags.a(href=guard.LOGOUT_AVATAR)["Logout"] ] ] ] ]) def __init__(self, avatarId=None): rend.Page.__init__(self) self.avatarId=avatarId def render_isLogged(self, context, data): q = inevow.IQ(context) true_pattern = q.onePattern('True') false_pattern = q.onePattern('False') if self.avatarId: return true_pattern or context.tag().clear() else: return false_pattern or context.tag().clear() def render_sessionId(self, context, data): sess = inevow.ISession(context) return context.tag[sess.uid] def logout(self): print("Bye")
def render_overwrite_form(self, ctx, data): node = self.original root = self.get_root(ctx) 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(class_="freeform-form-label")["Overwrite"], "Upload new contents: ", T.input(type="file", name="file"), " ", T.input(type="submit", value="Replace Contents") ]] return ctx.tag[overwrite]
def render_addroomform(self, ctx, data): action = '/rooms/add/' lines = [T.h2['Add Room']] roomclasses = rooms.classes() roomclasses.sort() choices = [(cls, cls) for cls in roomclasses] roomsinfo = dict(name='roomclass', choices=choices, selected='Room') row = T.tr[T.td[self.render_form_select(roomsinfo)], T.td[T.input(name='roomname')], T.td[T.input(type='submit', value=' Add ')]] tbl = T.table(_class="center")[row] lines.append(tbl) form = T.form(action=action, method='POST')[lines] return T.div(_class='addroom')[form]
def render_manifest_form(self, ctx, data): ophandle = base32.b2a(os.urandom(16)) manifest = T.form(action=".", method="post", enctype="multipart/form-data")[ T.fieldset[ T.input(type="hidden", name="t", value="start-manifest"), T.legend(class_="freeform-form-label")["Run a manifest operation (EXPENSIVE)"], T.div["Output Format: ", T.select(name="output") [ T.option(value="html", selected="true")["HTML"], T.option(value="text")["text"], T.option(value="json")["JSON"], ], ], T.input(type="hidden", name="ophandle", value=ophandle), T.input(type="submit", value="Manifest"), ]] return ctx.tag[manifest]
def render_reload(self, ctx, data): 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"), ] return [T.h2["Operation still running: ", T.a(href=reload_target)["Reload"], ], cancel_button, ]
def page_body(kwargs): merits = parse_merits(kwargs) checks = [gen_checks(b, merits) for b in ribbonator.bodies] job = '?' + '&'.join('='.join(gen_job(b, merits[b])) for b in merits if 'soi' in merits[b]) print 'serving index', job return [t.script(type='text/javascript')[PAGE_SCRIPT], t.h1['RSS Ribbonator - Clumsy Web Interface'], t.p["Generator and RSS Ribbons by Edward Cree. Based on the KSP Ribbons by Unistrut. 'Inspired' by ", t.a(href='http://www.kerbaltek.com/ribbons')["Ezriilc's Ribbon Generator"], "."], t.p[t.a(href="https://github.com/ec429/ribbonator")["Source Code"]], t.p["Select your achievements with the checkboxes and radiobuttons, and click Submit to generate the ribbon image URL. This will also generate a Ribbonator 'job card' URL; bookmark this if you want to be able to update your ribbons later."], t.p["Moons will only appear when their parent planet's 'Reached SOI' is selected."], t.p["The Ribbonator does not store any user data. Instead, the ribbon contents are encoded in the URL of the image, using the same 'job card' format."], t.p["I recommend against linking directly to the generated image. Download it, then upload to some other hosting; that way your image won't break if the Ribbonator moves, dies, or has bandwidth troubles."], t.img(src='gen.png'+job, alt="Generated ribbons"), t.p[t.a(href=job)["Job Card URL - bookmark this"] if len(job) > 1 else ''], t.form(method='GET')[t.ul[checks], t.input(type='submit', value='Submit') ], ]
def form(self, ctx, data): return t.div(_class="quick", id="replform_%s" % data.get('pid'))[ t.form(action="./freeform_post!!quick_reply", method="post")[ t.h3["Quote & Reply ", self.onclick ], t.fieldset[ t.label(_for="title_")["Title"], self.title, t.label(_for="content_")["Message", t.span[" (Markdown formatting rules are supported)"] ], self.body ], t.fieldset[ t.input(type="submit", name="Post Reply", value="Post Reply") ] ] ]
def render_mkdir_form(self, ctx, data): # this is a form where users can create new directories mdmf_input = T.input(type='radio', name='mutable-type', value='mdmf', id='mutable-directory-mdmf') sdmf_input = T.input(type='radio', name='mutable-type', value='sdmf', id='mutable-directory-sdmf', checked='checked') form = T.form(action="uri", method="post", enctype="multipart/form-data")[ T.fieldset[ T.legend(class_="freeform-form-label")["Create a directory"], T.label(for_='mutable-directory-sdmf')["SDMF"], sdmf_input, T.label(for_='mutable-directory-mdmf')["MDMF"], mdmf_input, T.input(type="hidden", name="t", value="mkdir"), T.input(type="hidden", name="redirect_to_result", value="true"), T.input(type="submit", value="Create a directory"), ]] return T.div[form]
def render_mkdir_form(self, ctx, data): # This is a form where users can create new directories. # Users can choose SDMF or MDMF from a radio button. mkdir_sdmf = T.input(type='radio', name='format', value='sdmf', id='mkdir-sdmf', checked='checked') mkdir_mdmf = T.input(type='radio', name='format', value='mdmf', id='mkdir-mdmf') form = T.form(action="uri", method="post", enctype="multipart/form-data")[ T.fieldset[ T.legend(class_="freeform-form-label")["Create a directory"], mkdir_sdmf, T.label(for_='mkdir-sdmf')[" SDMF"], SPACE, mkdir_mdmf, T.label(for_='mkdir-mdmf')[" MDMF (experimental)"], SPACE*2, T.input(type="hidden", name="t", value="mkdir"), T.input(type="hidden", name="redirect_to_result", value="true"), T.input(type="submit", value="Create a directory"), ]] return T.div[form]