Esempio n. 1
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)
Esempio n. 2
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)