def _formstyle_onx(form, fields, is_modal): form.add_class('form-horizontal onx-form') input_class = {True: 'span8', False: 'span4'} parent = FIELDSET() for id, label, controls, help in fields: # wrappers _help = SPAN(help, _class='help-block') # embed _help into _controls if isinstance(controls, DIV): wgt = controls.elements('.onx-widget') if wgt: controls.insert(1,_help) _controls = DIV(controls, _class='controls') else: _controls = DIV(controls, _help, _class='controls') else: _controls = DIV(controls, _help, _class='controls') # submit unflag by default _submit = False if isinstance(controls, INPUT): controls.add_class(input_class[is_modal]) if controls['_type'] == 'submit': # flag submit button _submit = True controls['_class'] = 'btn btn-success' if controls['_type'] == 'file': controls['_class'] = 'input-file' if controls['_type'] == 'checkbox': controls['_class'] = 'input-checkbox' # For password fields, which are wrapped in a CAT object. if isinstance(controls, CAT) and isinstance(controls[0], INPUT): controls[0].add_class(input_class[is_modal]) if isinstance(controls, SELECT): controls.add_class(input_class[is_modal]) if isinstance(controls, TEXTAREA): controls['_class'] = 'text %s' % 'span8' if is_modal else 'span6' if isinstance(label, LABEL): label['_class'] = 'control-label' if _submit: # submit button has unwrapped label and controls, different class parent.append(DIV(label, DIV(controls, _class='controls'), _class='row-fluid', _id=id)) # unflag submit (possible side effect) _submit = False else: # unwrapped label parent.append(DIV(label, _controls, _class='row-fluid', _id=id)) return parent
def mybootstrap(form, fields): ''' bootstrap format form layout ''' form.add_class('form-horizontal') parent = FIELDSET() for id, label, controls, help in fields: # wrappers _help = SPAN(help, _class='help-inline') if isinstance(controls, (str, int, SPAN)): controls = SPAN(controls, _class="input-xlarge uneditable-input") # embed _help into _controls _controls = DIV(controls, _help, _class='controls') # submit unflag by default _submit = False if isinstance(controls, INPUT): controls.add_class('input-xlarge') if controls['_type'] == 'submit': # flag submit button _submit = True controls['_class'] = 'btn btn-primary' if controls['_type'] == 'file': controls['_class'] = 'input-file' # For password fields, which are wrapped in a CAT object. if isinstance(controls, CAT) and isinstance(controls[0], INPUT): controls[0].add_class('input-xlarge') if isinstance(controls, SELECT): controls.add_class('input-xlarge') if isinstance(controls, TEXTAREA): controls['_rows'] = 1 controls.add_class('input-xlarge') if isinstance(label, LABEL): label['_class'] = 'control-label' if _submit: # submit button has unwrapped label and controls, different class parent.append(DIV(label, controls, _class='form-actions', _id=id)) # unflag submit (possible side effect) _submit = False else: # unwrapped label parent.append(DIV(label, _controls, _class='control-group', _id=id)) script = SCRIPT(""" $(function() { $('<span class="help-block">' + $('.error_wrapper .error').text() + '</span>'). appendTo($('.error_wrapper').closest('.controls')); $('.error_wrapper').hide().closest('.control-group').addClass('error'); })""") parent.append(script) return parent
def mybootstrap(form, fields): ''' bootstrap format form layout ''' form.add_class('form-horizontal') parent = FIELDSET() for id, label, controls, help in fields: # wrappers _help = None if help: _help = SPAN(help, _class='help-block') if isinstance(controls, (str, int, SPAN)): controls = P(controls, _class="form-control-static") # submit unflag by default _submit = False if isinstance(controls, INPUT): if controls['_type'] == 'submit': # flag submit button _submit = True controls['_class'] = 'btn btn-primary' if controls['_type'] == 'file': controls['_class'] = 'input-file' if isinstance(label, LABEL): label['_class'] = 'col-sm-2 control-label' if _submit: # submit button has unwrapped label and controls, different class parent.append(DIV(DIV(controls,_class="col-sm-offset-2 col-sm-10"), _class='form-group form-group-sm', _id=id)) # unflag submit (possible side effect) _submit = False else: # unwrapped label if _help: parent.append(DIV(label, DIV(controls, _help, _class="col-sm-10"), _class='form-group form-group-sm', _id=id)) else: parent.append(DIV(label, DIV(controls, _class="col-sm-10"), _class='form-group form-group-sm', _id=id)) return parent
def test_FIELDSET(self): self.assertEqual( FIELDSET('<>', _a='1', _b='2').xml(), b'<fieldset a="1" b="2"><></fieldset>')