def html_hidden(self, context): default = context.default(self) if not isinstance(default, (tuple, list)): if default is None: default = [] else: default = [default] return html( [html.input.hidden(name=context.name(self), value=value) for value in default])
def render(self, context): if self.name: restore = context.push_attr(add_name=self.name+'.') else: restore = None try: if self.hidden: return html([f.html_hidden(context) for f in self.fields]) normal = [] hidden = [] for field in self.fields: if field.hidden: hidden.append(field.render(context)) else: normal.append(field) return html(self.wrap(hidden, normal, context)) finally: if restore: restore.pop_attr()
def render(self, context): assert self.action, "You must provide an action" contents = html( [f.render(context) for f in self.fields]) enctype = self.enctype for field in self.fields: if field.enctype: if enctype is None or enctype == field.enctype: enctype = field.enctype else: raise ValueError( "Conflicting enctypes; need %r, field %r wants %r" % (enctype, field, field.enctype)) return html.form( action=self.action, method=self.method, name=context.name(self), id=context.id(self), enctype=enctype, c=contents)
def html_line(self, line, fields, context): """ Formats lines: '=text' means a literal of 'text', 'name' means the named field, ':name' means the named field, but without a label. """ cells = [] for item in line: if item.startswith('='): cells.append(html.td(item)) continue if item.startswith(':'): field = fields[item[1:]] label = '' else: field = fields[item] label = self.format_label(field, context) if label: label = html(label, html.br) cells.append(html.td('\n', label, field.render(context), valign="bottom")) cells.append('\n') return html.table(html.tr(cells))
def wrap_field(self, field, context): return html(self.format_label(field, context), field.render(context), html.br)
def html_static(self, context): return html( self.html_hidden(context), context.default(self))