예제 #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 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)
예제 #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 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)
예제 #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 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)
예제 #7
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)
예제 #8
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)
예제 #9
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)
예제 #10
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)