def render_input(self, context, data): formDefaults = context.locate(iformless.IFormDefaults) methodDefaults = formDefaults.getAllDefaults('search') conf = self.configurable_(context) for k,v in conf: methodDefaults[k] = v return webform.renderForms()
def render_form_service(self, ctx, data): # TODO error messages for one password change form display in # all of them. e = inevow.IData(ctx) for name in self.listServicePasswordActions(): yield webform.renderForms('service_%s_%s' % (name, e.dn))[ctx.tag()]
class DBBrowser(rend.Page): implements(IAddItem) addSlash = True def addItem(self, newSubject): doQuery('insert into foo values subject = "%s"', newSubject) def data_queryDatabase(self, context, data): return doQuery('select * from foo') def render_row(self, context, data): theId, theSubj = data return context.tag[ # put our anchor in the li provided by the template tags.a(href=theId)[theSubj]] docFactory = loaders.stan(tags.html[tags.body[ tags.h1["Welcome, user"], tags.ul(data=tags.directive("queryDatabase"), render=tags.directive("sequence") )[tags.li(pattern="item", render=render_row)], webform.renderForms()]]) def childFactory(self, ctx, name): """Since we created anchor tags linking to children of this resource directly by id, when the anchor is clicked, childFactory will be called with the appropriate id as the name argument.""" try: ## Pass the id of the database item we want to be rendered on this page ## to the DBItem constructor. This integer will be used as the default data ## for this page. return DBItem(int(name)) except ValueError: pass
class DBItem(rend.Page): implements(IItemWithSubject) addSlash = True def setSubject(self, newSubject): ## Self.original is the data that was passed to the DBItem constructor above; the id of this record doQuery('update foo set subject = "%s" where id = %s', newSubject, self.original) def render_viewSelector(self, context, data): args = inevow.IRequest(context).args view = args.get('view', ['view'])[0] if view == 'view': selector = "View | ", tags.a(href=here.add('view', 'edit'))["Edit"] editor = '' else: selector = tags.a(href=here.add('view', 'view'))["View"], " | Edit" editor = context.onePattern( 'edit')() # get one copy of the edit pattern viewer = context.onePattern( 'view')() # get one copy of the view pattern return selector, viewer, editor def render_itemDetail(self, context, data): theId, theSubject = doQuery('select * from foo where id = %s', self.original)[0] return tags.h2["Object ", theId], tags.span["Subject: ", theSubject] docFactory = loaders.stan( tags.html[tags.body[tags.p[tags.a(href=here.parent())["Up"]], tags.div(render=render_viewSelector)[ tags.p(pattern="edit")[webform.renderForms()], tags.p(pattern="view")[render_itemDetail]]]])
class Root(TransactionalPage): child_webform_css = webform.defaultCSS implements(IInsert) docFactory = loaders.stan(t.html[ t.head[t.title['Imagination'], t.link(rel='stylesheet', type='text/css', href=url.root.child('webform_css'))], t.body[webform.renderForms(), t.ul(render=t.directive("sequence"), data=t.directive("images") )[t.li(pattern="item", render=t.directive("image")), t.li(pattern="empty")["No images yet"]]]]) def data_images(self, ctx, data): return IImages(self.store).getImages(15) def render_image(self, ctx, data): return t.a(href=url.root.child('fs').child(data.hash))[data.title] def insert(self, ctx, title, author, image): img = Image(store=self.store, image=image.value, title=title.decode('utf-8'), author=author.decode('utf-8'), hash=label().decode('utf-8')) def locateChild(self, ctx, segments): if segments[0] == 'fs': data = IImages(self.store).getOne(segments[1].decode('utf-8')) return static.Data(data.image, 'image/jpeg'), () return super(Root, self).locateChild(ctx, segments)
class FormPage(rend.Page): addSlash = True child_webform_css = webform.defaultCSS def render_hand(self, ctx, data): hand = inevow.IHand(ctx, None) if hand is not None: return ctx.tag[hand] return '' docFactory = loaders.stan( tags.html[ tags.head[ tags.link(rel='stylesheet', type='text/css', href=url.here.child('webform_css')), ], tags.body[ tags.h3(render=render_hand, style="color: red; font-size: xx-large"), "Hello! Here is a form:", # We want to render forms defined by the Implementation instance. # When we pass the Implementation instance to FormPage below, # rend.Page sets it as the .original attribute. To tell webform to render # forms described by this object, we use the configurable name "original". webform.renderForms('original'), ], ], )
def render_form(self, ctx, data): conf = getSearchForm(ctx) formDefaults = ctx.locate(iformless.IFormDefaults) methodDefaults = formDefaults.getAllDefaults('search') for k,v in conf.data.items(): if v is not None: methodDefaults[k] = str(v) return webform.renderForms()
class Redirector(rend.Page): docFactory = loaders.stan(tags.html[tags.body[webform.renderForms()]]) def bind_goHome(self, ctx): return [] def goHome(self): return url.root
def render_form(self, ctx, data): conf = getSearchForm(ctx) formDefaults = ctx.locate(iformless.IFormDefaults) methodDefaults = formDefaults.getAllDefaults("search") for k, v in conf.data.items(): if v is not None: methodDefaults[k] = str(v) return webform.renderForms()
def render_form(self, context, data): if self.version != -1: return '' version = self.pasting.getVersion(self.version) formDefaults = context.locate(iformless.IFormDefaults) formDefaults.setDefault('editPasting.text', version.getText()) formDefaults.setDefault('editPasting.postedBy', version.getAuthor()) return webform.renderForms()
def render_forms(self, ctx, data): d = iformless.IFormDefaults(ctx).getAllDefaults('insert') d['author'] = self.original.author d['category'] = self.original.category d['title'] = self.original.title d['content'] = self.original.content d['id'] = self.original.id return webform.renderForms()
def renderForms(self, configurable, ctx=None, *args, **kwargs): self.conf = configurable if ctx is None: ctx = self.setupContext(False) ctx.remember(self, iformless.IConfigurableFactory) return self.render( webform.renderForms(*args, **kwargs), setupContext=lambda c: ctx)
class Root(rend.Page): implements(ITodo) child_css = webform.defaultCSS docFactory = loaders.stan( t.html(render=t.directive("time"))[ t.head[ t.title['todo'], t.style(type="text/css")[".done { color: #dddddd; }"], t.style(type="text/css")["@import url(/css);"] ], t.body[ webform.renderForms(), t.ul(data=t.directive("findAll"), render=t.directive("sequence"))[ t.li(pattern="item",render=t.directive('todo')), t.li(pattern="empty",render=t.directive('empty')), ], t.p(render=t.directive("end")) ] ] ) def insert(self, ctx, description): return itodo.ITodos(ctx).add(description, 0) def delete(self, ctx, id): return itodo.ITodos(ctx).delete(id) def update(self, ctx, id, oldstate): newstate = [1, 0][oldstate] return itodo.ITodos(ctx).update(id, newstate) def data_findAll(self, ctx, data): return itodo.ITodos(ctx).findAll() def render_todo(self, ctx, data): deluri = "freeform_post!!delete?id="+str(data[0]) updateuri = "freeform_post!!update?id="+str(data[0])+"&oldstate="+str(data[2]) state = [" Done", " To Do"][int(data[2])==0] tag = ctx.tag if data[2]: tag = ctx.tag(_class="done") return tag[data[1]+" - ", t.a(href=deluri)["Delete"], " / ", t.a(href=updateuri)[("Mark Done", "Mark Undone")[data[2]]], state] def render_empty(self, ctx, data): return ctx.tag["No Todos"] def render_time(self, ctx, data): ctx.remember(now(), itodo.ITimer) return ctx.tag def render_end(self, ctx, data): return ctx.tag["%.3f"%(now()-itodo.ITimer(ctx))]
def render_userForm(self, context, form): isAdmin = "No" if (self.user.isAdmin()): isAdmin = "Yes" return webform.renderForms( 'modifyUserForm', bindingDefaults={'modifyUser': { 'isAdministrator': isAdmin }})
class NameWizard(rend.Page): docFactory = loaders.stan(tags.html[tags.h1["What is your name"], webform.renderForms()]) def bind_name(self, ctx): return [('name', annotate.String())] def name(self, name): return QuestWizard(name)
def extensions_settings(self, context, data): """ Project extensions settings Extensions added to Configuration Tree in IDE have their setting rendered here """ global extensions_settings_od res = [] for token in extensions_settings_od: _settings, display = extensions_settings_od[token] res += [tags.h2[display], webform.renderForms(token)] return res
class FinalWizard(rend.Page): docFactory = loaders.stan(tags.html[ tags.h1["What is the airspeed velocity of an unladen swallow"], webform.renderForms()]) def bind_speed(self, ctx): return [('speed', annotate.Integer())] def speed(self, speed): return rend.Page(docFactory=loaders.stan(tags.html[tags.body( id='body')["Thanks for taking our survey! You said: %r %r %r" % (self.original[0], self.original[1], speed)]]))
class QuestWizard(rend.Page): docFactory = loaders.stan(tags.html[tags.h1["What is your quest"], webform.renderForms()]) def bind_quest(self, ctx): return [('quest', annotate.Choice([ 'Find the Grail', 'Get laid', 'Earn twenty bucks', 'Destroy the sun' ]))] def quest(self, quest): return FinalWizard((self.original, quest))
def _cb(cfg, ctx): bindingDefaults = {} bindingDefaults.setdefault("edit", {}) bindingDefaults.setdefault("subscribe", {}) bindingDefaults.setdefault("unsubscribe", {}) ( bindingDefaults["edit"]["subscription"], bindingDefaults["edit"]["posting"], bindingDefaults["edit"]["mail-on-subscription-changes"], bindingDefaults["edit"]["mail-on-forced-unsubscribe"], bindingDefaults["edit"]["description"], ) = cfg return ctx.tag[webform.renderForms("owner", bindingDefaults=bindingDefaults),]
class FormPage(rend.Page): addSlash = True child_webform_css = webform.defaultCSS # We need this to implement IMyForm foo = 5 docFactory = loaders.stan( tags.html[tags.head[ tags.link(rel='stylesheet', type='text/css', href=url.here.child('webform_css')), ], tags.body[ "Hello! Here is a form:", # We want to render the "default" configurable. # This is located in Page.configurable_() and is going to be # 'self' (which, as you see above, implements IMyForm). webform.renderForms(), ], ], )
class DataEntry(rend.Page): """Add Animal""" addSlash = 1 docFactory = loaders.stan( T.html[T.body[T.h1[ "First, a Setup Form."], T.h2["Enter some animals as data. Click 'Done' to test looking up these animals."], T.h3["The neat stuff happens when you hit 'Done'."], webform.renderForms(), T.ol(data=T.directive("animals"), render=rend.sequence)[ T.li(pattern="item", render=T.directive("string")), ], T.h1[T.a(href=url.here.child('typeahead'))["Done"]], ] ] ) def bind_animals(self, ctx, ): """Add Animal""" return annotate.MethodBinding( 'animals', annotate.Method(arguments= [annotate.Argument('animal', annotate.String()), annotate.Argument('description', annotate.Text())]), action="Add Animal", ) def animals(self, animal, description): """Add Animal""" if not (animal and description): return animals[animal.decode('utf-8')] = description.decode('utf-8') return url.here def data_animals(self, ctx, data): return list(animals.keys()) def child_typeahead(self, ctx): return TypeAheadPage(None, None)
def render_form(self, ctx, data): return ctx.tag[webform.renderForms()]
def render_customForm(self, ctx, data): return webform.renderForms()[FORM_LAYOUT]
def render_loginForm(self, loginForm): return webform.renderForms()
def render_configBody(self, ctx, data): return webform.renderForms(bindingNames=[ctx.arg('config_type')])
def renderBody (self, ctx, data): return T.body[webform.renderForms()]
def render_objectClassForm(self, context, data): return webform.renderForms('objectClass')
def render_smartObjectForm(self, context, data): if self.havePlugins(): return webform.renderForms('smartObject') else: return context.tag.clear()
def render_forms(self, ctx, data): d = iformless.IFormDefaults(ctx).getAllDefaults('insert') d['author'] = 'Anonymous' d['id'] = IBlog(IStore(ctx)).getNextId() return webform.renderForms()
def render_add(self, ctx, data): return webform.renderForms('add')
def render_form_admin(self, ctx, data): return ctx.tag[webform.renderForms("admin"),]
def render_descriptionForm(self, context, data): return webform.renderForms()
def render_content(self, context, data): tag = context.tag.clear() return tag[webform.renderForms()]
def _gotDefaults(bindingDefaults, ctx): return ctx.tag[webform.renderForms("user", bindingDefaults=bindingDefaults),]
def render_bulletinForm(self, context, data): return webform.renderForms('bulletinForm')
def render_move(self, context, data): return webform.renderForms("move_%s" % data.dn)[context.tag]
def render_userForm(self, context, form): isAdmin = "No" if (self.user.isAdmin()): isAdmin = "Yes" return webform.renderForms('modifyUserForm', bindingDefaults = {'modifyUser': {'isAdministrator' : isAdmin}})
def render_form(self, context, data): return webform.renderForms()
def render_form(self, ctx, data): return webform.renderForms()
def render_form(self, ctx, data): return webform.renderForms(bindingNames=["insert"])[ctx.tag]
def test_deferredProperty(self): class IDeferredProperty(formless.TypedInterface): d = formless.String() from nevow import util deferred = util.Deferred() deferred.callback('the default value') class Implementation(object): implements(IDeferredProperty) d = deferred return deferredRender(rend.Page(Implementation(), docFactory=loaders.stan(html[freeform.renderForms('original')]))).addCallback( lambda result: self.assertIn('value="the default value"', result))
def render_form(self, ctx, data): defaults=iformless.IFormDefaults(ctx).getAllDefaults('quick_reply') defaults['title'] = "Re: "+iweb.IMainTitle(ctx, '') return webform.renderForms()[ctx.tag]