示例#1
0
文件: layout.py 项目: victorlv/uliweb
 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
示例#2
0
文件: layout.py 项目: znanl/uliweb
    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)
示例#3
0
    def html(self):
        if self.table_cell:
            if self.error:
                error = self.get_error()
                error_class = ' has-error'
            else:
                error = ''
                error_class = ''

            return ('<div class="table-field-row%s">' % error_class + self.label +
                    '<div class="table-field-col">' + self.content +
                    error + '</div></div>')

        col_cls = 'form-group'
        if self.error:
            col_cls = col_cls + ' has-error'
        if self.name:
            _id = 'div_field_%s' % self.name
        else:
            _id = None

        buf = Buf()
        with buf.div(_class=col_cls, id=_id):
            buf << self.label
            if self.dir == 'h':
                if self.label:
                    buf << '<div class="col-sm-%d">' % (12-self.label_width)
                else:
                    buf << '<div class="col-sm-offset-%d col-sm-%d">' % (self.label_width,
                                                                         12-self.label_width)
            # buf << '<div class="table-field-row">'
            buf << self.content
            # buf << '</div>'
            buf << self.get_help_string()
            if self.error:
                buf << self.get_error()
            if self.dir == 'h':
                buf << '</div>'

        return str(buf)
示例#4
0
 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)
示例#5
0
    def line(self, line):
        result = []
        columns_num = len(line)
        total_width = 0
        for f in line:
            if isinstance(f, (str, unicode)):
                col = {'name':f}
            elif isinstance(f, dict):
                col = f
            elif isinstance(f, (tuple, list)):
                col = {'name':'', 'cols':f}
            else:
                raise Exception("layout line should be string, list or dict, but %r found" % f)
            width, r = self.process_column(col, columns_num)
            total_width += width
            result.append((width, r))

        b = Buf()
        if columns_num == 1:
            if self.use_table:
                with b.tr:
                    with b.td(colspan=12):
                        b << result[0][1]
            else:
                b << result[0][1]
        else:
            if self.use_table:
                with b.tr:
                    for width, r in result:
                        span = width * 12 / total_width
                        with b.td(colspan=span, width='%f%%' % (span *100.0/12)):
                            b << r
            else:
                with b.div(_class="row"):
                    for width, r in result:
                        col_cls = 'col-sm-%d' % (width * 12 / total_width)
                        with b.div(_class=col_cls):
                            b << r
        return str(b)
示例#6
0
    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)
示例#7
0
 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)
示例#8
0
 def body(self):
     buf = Buf()
     self.process_layout(buf)
     return str(buf)