示例#1
0
 def testReuse(self):
     t = HtmlTable()
     t.addColumn(Column(label="c1"))
     html = t.render((1, 2))
     self.assertEqualsWS("<table><thead><tr><th>c1</th></tr></thead><tfoot></tfoot><tbody><tr><td>1</td></tr><tr><td>2</td></tr></tbody></table>", html)
     html = t.render((3, 4))
     self.assertEqualsWS("<table><thead><tr><th>c1</th></tr></thead><tfoot></tfoot><tbody><tr><td>3</td></tr><tr><td>4</td></tr></tbody></table>", html)
示例#2
0
 def testMyOwnRendering(self):
     class CustomColumn(Column):
        def cell_content(self, item, parent, **kwargs):
            yield str(item).swapcase() + parent
     t = HtmlTable()
     t.addColumn(CustomColumn(label='c1'))
     html = t.render(items=['aa<p'], parent='fiets')
     self.assertEqualsWS(
             '<table>'
             '<thead><tr><th>c1</th></tr></thead>'
             '<tfoot></tfoot>'
             '<tbody>'
                 '<tr><td>AA&lt;Pfiets</td></tr>'
             '</tbody></table>', html)
示例#3
0
 def testMyOwnRendering(self):
     class CustomColumn(Column):
        def cell_content(self, item, parent, **kwargs):
            yield str(item).swapcase() + parent
     t = HtmlTable()
     t.addColumn(CustomColumn(label='c1'))
     html = t.render(items=['aa<p'], parent='fiets')
     self.assertEqualsWS(
             '<table>'
             '<thead><tr><th>c1</th></tr></thead>'
             '<tfoot></tfoot>'
             '<tbody>'
                 '<tr><td>AA&lt;Pfiets</td></tr>'
             '</tbody></table>', html)
示例#4
0
 def testPrevCurNext(self):
     class PrevCurNextColumn(Column):
         def cell_content(self, item, prevItem, nextItem, **kwargs):
             yield '{} {} {}'.format(prevItem or '-', item, nextItem or '-')
     t = HtmlTable()
     t.addColumn(PrevCurNextColumn(label="label"))
     html = t.render([1,2,3])
     self.assertEqualsWS('<table>'
         '<thead><tr><th>label</th></tr></thead>'
         '<tfoot></tfoot>'
         '<tbody>'
         '<tr><td>- 1 2</td></tr>'
         '<tr><td>1 2 3</td></tr>'
         '<tr><td>2 3 -</td></tr>'
         '</tbody>'
         '</table>', html)
示例#5
0
 def testPrevCurNext(self):
     class PrevCurNextColumn(Column):
         def cell_content(self, item, prevItem, nextItem, **kwargs):
             yield '{} {} {}'.format(prevItem or '-', item, nextItem or '-')
     t = HtmlTable()
     t.addColumn(PrevCurNextColumn(label="label"))
     html = t.render([1,2,3])
     self.assertEqualsWS('<table>'
         '<thead><tr><th>label</th></tr></thead>'
         '<tfoot></tfoot>'
         '<tbody>'
         '<tr><td>- 1 2</td></tr>'
         '<tr><td>1 2 3</td></tr>'
         '<tr><td>2 3 -</td></tr>'
         '</tbody>'
         '</table>', html)
示例#6
0
 def testReuse(self):
     t = HtmlTable()
     t.addColumn(Column(label="c1"))
     html = t.render((1, 2))
     self.assertEqualsWS("<table><thead><tr><th>c1</th></tr></thead><tfoot></tfoot><tbody><tr><td>1</td></tr><tr><td>2</td></tr></tbody></table>", html)
     html = t.render((3, 4))
     self.assertEqualsWS("<table><thead><tr><th>c1</th></tr></thead><tfoot></tfoot><tbody><tr><td>3</td></tr><tr><td>4</td></tr></tbody></table>", html)
示例#7
0
 def testColumnWithColspan(self):
     class OneHeadTwoCells(Column):
         def head_tag(self, **kwargs):
             return Column.head_tag(self).set('colspan', '2')
         def colspan(self):
             return 2
         def cell_tag(self, **kwargs):
             return self.tag(None)
         def cell_content(self, item, **kwargs):
             with self.tag('td'):
                 yield '1-{}'.format(item)
             with self.tag('td'):
                 yield '2-{}'.format(item)
     t = HtmlTable()
     t.addColumn(OneHeadTwoCells(label="label"))
     html = t.render(("a", "b"))
     self.assertEqualsWS('<table>'
         '<thead><tr><th colspan="2">label</th></tr></thead>'
         '<tfoot></tfoot>'
         '<tbody>'
         '<tr><td>1-a</td><td>2-a</td></tr>'
         '<tr><td>1-b</td><td>2-b</td></tr>'
         '</tbody>'
         '</table>', html)
示例#8
0
 def testColumnWithColspan(self):
     class OneHeadTwoCells(Column):
         def head_tag(self, **kwargs):
             return Column.head_tag(self).set('colspan', '2')
         def colspan(self):
             return 2
         def cell_tag(self, **kwargs):
             return self.tag(None)
         def cell_content(self, item, **kwargs):
             with self.tag('td'):
                 yield '1-{}'.format(item)
             with self.tag('td'):
                 yield '2-{}'.format(item)
     t = HtmlTable()
     t.addColumn(OneHeadTwoCells(label="label"))
     html = t.render(("a", "b"))
     self.assertEqualsWS('<table>'
         '<thead><tr><th colspan="2">label</th></tr></thead>'
         '<tfoot></tfoot>'
         '<tbody>'
         '<tr><td>1-a</td><td>2-a</td></tr>'
         '<tr><td>1-b</td><td>2-b</td></tr>'
         '</tbody>'
         '</table>', html)
示例#9
0
 def testColumnBasics(self):
     self.maxDiff = None
     st = HtmlTable()
     st.addColumn(Column(label='Label'))
     st.addColumn(Column(label='<label>'))
     html = st.render(items=(1,2,3))
     self.assertEqualsWS(
         '<table>'
         '<thead>'
         '<tr><th>Label</th><th>&lt;label&gt;</th></tr>'
         '</thead>'
         '<tfoot></tfoot>'
         '<tbody>'
         '<tr><td>1</td><td>1</td></tr>'
         '<tr><td>2</td><td>2</td></tr>'
         '<tr><td>3</td><td>3</td></tr>'
         '</tbody>'
         '</table>', html)
示例#10
0
 def testColumnBasics(self):
     self.maxDiff = None
     st = HtmlTable()
     st.addColumn(Column(label='Label'))
     st.addColumn(Column(label='<label>'))
     html = st.render(items=(1,2,3))
     self.assertEqualsWS(
         '<table>'
         '<thead>'
         '<tr><th>Label</th><th>&lt;label&gt;</th></tr>'
         '</thead>'
         '<tfoot></tfoot>'
         '<tbody>'
         '<tr><td>1</td><td>1</td></tr>'
         '<tr><td>2</td><td>2</td></tr>'
         '<tr><td>3</td><td>3</td></tr>'
         '</tbody>'
         '</table>', html)
示例#11
0
 def foot_tag(self, **kwargs):
     return HtmlTable.foot_tag(self, **kwargs).delete('tag')
示例#12
0
 def row_tag(self, **kwargs):
     return HtmlTable.row_tag(self, **kwargs).append('class', 'my-row')
示例#13
0
 def head_row_tag(self, **kwargs):
     return HtmlTable.head_row_tag(self, **kwargs).append('class', 'my-head-row')
示例#14
0
 def head_tag(self, **kwargs):
     return HtmlTable.head_tag(self, **kwargs).set('class', ['my-head'])
示例#15
0
 def table_tag(self, **kwargs):
     return HtmlTable.table_tag(self, **kwargs).append('class', 'my-table')
示例#16
0
 def table_tag(self, **kwargs):
     return HtmlTable.table_tag(self, **kwargs).append('class', 'my-table')
示例#17
0
 def head_tag(self, **kwargs):
     return HtmlTable.head_tag(self, **kwargs).set('class', ['my-head'])
示例#18
0
 def foot_tag(self, **kwargs):
     return HtmlTable.foot_tag(self, **kwargs).delete('tag')
示例#19
0
 def row_tag(self, **kwargs):
     return HtmlTable.row_tag(self, **kwargs).append('class', 'my-row')
示例#20
0
 def head_row_tag(self, **kwargs):
     return HtmlTable.head_row_tag(self, **kwargs).append('class', 'my-head-row')