def child(self, context, n): args = [] if n.find(' ') != -1: name, args = n.split(None, 1) args = [arg.strip() for arg in args.split(',')] else: name = n callable = getattr(self, 'data_%s' % name, None) ## If this page doesn't have an appropriate data_* method... if callable is None: ## See if our self.original has an IContainer... container = inevow.IContainer(self.original, None) if container is None: util.log.msg( "ERROR: The data named '%s' was not found in %r." % (name, self)) callable = lambda context, data: context.tag[ "The data named '%s' was not found in %r." % (name, self)] else: ## And delegate to it if so. return container.child(context, n) if args: return callable(*args) return callable
def postForm(self, ctx, bindingName, args): """Accept a form post to the given bindingName. The bindingName can be dotted to indicate an attribute of this Configurable, eg addresses.0.changeEmail. The post arguments are given in args. Return a Resource which will be rendered in response. """ from formless import iformless from nevow.tags import invisible request = ctx.locate(inevow.IRequest) pathSegs = bindingName.split('.') configurable = self cf = ctx.locate(iformless.IConfigurableFactory) ## Get the first binding firstSeg = pathSegs.pop(0) binding = configurable.getBinding(ctx, firstSeg) ctx.remember(binding, IBinding) ctx.remember(configurable, IConfigurable) ## I don't think this works right now, it needs to be fixed. ## Most cases it won't be triggered, because we're just traversing a ## single binding name for seg in pathSegs: assert 1 == 0, "Sorry, this doesn't work right now" binding = configurable.getBinding(ctx, seg) child = self.boundTo if not isinstance(binding, GroupBinding): accessor = inevow.IContainer(configurable.boundTo, None) if accessor is None: child = getattr(configurable.boundTo, binding.name) else: child = accessor.child(ctx, binding.name) ## If it's a groupbinding, we don't do anything at all for this path segment ## This won't work right now. We need to push the previous configurable ## as the configurableFactory somehow and ask that for hte next binding ## we also need to support deferreds coming back from locateConfigurable assert 'black' is 'white', "Deferred support is pending" configurable = cf.locateConfigurable(ctx, child) ctx = WovenContext(ctx, invisible(key=seg)) ctx.remember(binding, IBinding) ctx.remember(configurable, IConfigurable) bindingProcessor = iformless.IInputProcessor(binding) rv = bindingProcessor.process(ctx, binding.boundTo, args) ctx.remember(rv, inevow.IHand) ctx.remember('%r success.' % bindingName, inevow.IStatusMessage) return rv