def body(self): if self.layout: m = [] for line in self.layout: if isinstance(line, (tuple, list)): _x = 0 for f in line: if isinstance(f, (str, unicode)): _x += 1 elif isinstance(f, dict): _x += f.get('colspan', 1) else: raise Exception, 'Colume definition is not right, only support string or dict' m.append(_x) else: m.append(1) n = min_times(m) else: self.layout = [name for name, obj in self.form.fields_list] n = 1 buf = Buf() table = None fieldset = None first = True cls = self.table_class for fields in self.layout: if not isinstance(fields, (tuple, list)): if isinstance(fields, (str, unicode)) and fields.startswith( '--') and fields.endswith('--'): #THis is a group line if table: buf << '</tbody></table>' if fieldset: buf << '</fieldset>' title = fields[2:-2].strip() if title: fieldset = True buf << '<fieldset><legend>%s</legend>' % title buf << '<table class="%s"><tbody>' % cls table = True first = False continue else: fields = [fields] if first: first = False buf << '<table class="%s"><tbody>' % cls table = True buf << self.line(fields, n) #close the tags if table: buf << '</tbody></table>' if fieldset: buf << '</fieldset>' return str(buf)
def html(self): s = Buf() for v, caption in self.choices: args = {'value': v} id = args.setdefault('id', 'radio_%d' % self.get_id()) args['name'] = self.kwargs.get('name') if v == self.value: args['checked'] = None div = Div(_class='type-check') div << Radio(**args) div << Tag('label', caption, _for=id) s << div return str(s)
def line(self, obj, label, input, help_string='', error=None): buf = Buf() with buf.td: buf << label if error: with buf.td(_class='error'): buf << input buf << error else: with buf.td: buf << input return buf
def body(self): buf = Buf() if self.form.fieldset: form = buf << Tag('fieldset') if self.form.form_title: form << Tag('legend', self.form.form_title) else: form = buf for name, obj in self.form.fields_list: f = getattr(self.form, name) if self.is_hidden(obj): form << f else: form << self.line(obj, f.label, f, f.help_string, f.error) return str(buf)
def body(self): buf = Buf() if not self.layout: self.layout = [name for name, obj in self.form.fields_list] self.process_layout(buf) return str(buf)
def body(self): buf = Buf() self.process_layout(buf) return str(buf)