# encoding=utf-8 import tornado.escape import tornado.web class FormUIModule(tornado.web.UIModule): def render(self, form, action='', method='post', submit=None, submit_sm=False): strings = [ '
'.format( action=action, method=method), self.handler.xsrf_form_html() ] for field in form: error = ' has-error' if len(field.errors) > 0 else '' strings.append('
') if field.type == 'BooleanField': strings.append('
') strings.append(field()) strings.append(field.label()) strings.append('
') else: strings.append(field.label(class_='control-label col-sm-2')) strings.append('
') strings.append(field(class_='form-control')) for error in field.errors: strings.append('
') strings.append(tornado.escape.xhtml_escape(error)) strings.append('
') strings.append('
') strings.append('
') if submit: btn_sm = ' btn-sm' if submit_sm else '' strings.append('') strings.append('
') return ''.join(strings)