def line(self, fields, n): _x = 0 for _f in fields: if isinstance(_f, string_types): _x += 1 elif isinstance(_f, dict): _x += _f.get('colspan', 1) else: raise Exception( 'Colume definition is not right, only support string or dict' ) tr = Tag('tr', newline=True) with tr: for x in fields: _span = int(n / _x) if isinstance(x, string_types): name = x elif isinstance(x, dict): name = x['name'] _span = _span * x.get('colspan', 1) f = getattr(self.form, name) obj = self.form.fields[name] #process hidden field if self.is_hidden(obj): #tr << f continue _class = "control-group" if f.error: _class = _class + ' error' with tr.td(colspan=_span, width='%d%%' % (100 * _span / n, ), valign='top'): with tr.Div(_class=_class, id='div_' + obj.id): if self.get_widget_name(obj) == 'Checkbox': tr << " " else: if self.label_fix: tr << f.field.get_label(_class='label_fix') else: tr << f.get_label(_class='control-label') div = Div(_class='controls') with div: if self.get_widget_name(obj) == 'Checkbox': div << f div << f.label else: div << f div << Div(_class="help help-block", _value=f.help_string or '') if f.error: div << Div(_class="message help-block", _value=f.error) tr << str(div) return tr
def line(self, fields, n): _x = 0 for _f in fields: 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' tr = Tag('tr', newline=True) with tr: for x in fields: _span = n / _x if isinstance(x, (str, unicode)): name = x elif isinstance(x, dict): name = x['name'] _span = _span * x.get('colspan', 1) f = getattr(self.form, name) obj = self.form.fields[name] #process hidden field if self.is_hidden(obj): tr << f continue _class = self.get_class(obj) if f.error: _class = _class + ' error' with tr.td(colspan=_span, width='%d%%' % (100 * _span / n, ), valign='top'): with tr.Div(_class=_class, id='div_' + obj.id): if f.error: tr.strong(f.error, _class="message") if self.get_widget_name(obj) == 'Checkbox': tr << f tr << f.label tr << f.help_string or ' ' else: if self.label_fix: tr << f.field.get_label( _class='field label_fix') else: tr << f.label tr << f tr << f.help_string or ' ' return tr