예제 #1
0
def test_render_table_to_response():
    class TestTable(NoSortTable):
        foo = Column(display_name="Bar")

    data = [Struct(foo="foo")]

    response = render_table_to_response(RequestFactory().get('/'), TestTable(data))
    assert isinstance(response, HttpResponse)
    assert '<table' in response.content
예제 #2
0
def readme_example_2(request):
    fill_dummy_data()

    class BarTable(Table):
        select = Column.select()  # Shortcut for creating checkboxes to select rows
        b__a = Column.number()  # Show "a" from "b". This works for plain old objects too.
        c = Column(bulk=True)  # The form is created automatically

    return render_table_to_response(request, BarTable(Bar.objects.all()), template_name='base.html', paginate_by=20)
예제 #3
0
def readme_example_1(request):
    # Say I have a class...
    class Foo(object):
        def __init__(self, i):
            self.a = i
            self.b = 'foo %s' % (i % 3)
            self.c = (i, 1, 2, 3, 4)

    # and a list of them
    foos = [Foo(i) for i in xrange(4)]

    # I can declare a table:
    class FooTable(Table):
        a = Column.number()  # This is a shortcut that results in the css class "rj" (for right justified) being added to the header and cell
        b = Column()
        c = Column(cell_format=lambda value: value[-1])  # Display the last value of the tuple
        sum_c = Column(cell_value=lambda row: sum(row.c), sortable=False)  # Calculate a value not present in Foo

    # now to get an HTML table:
    return render_table_to_response(request, FooTable(foos), template_name='base.html')
예제 #4
0
def kitchen_sink(request):
    fill_dummy_data()

    class BarTable(Table):
        select = Column.select()  # Shortcut for creating checkboxes to select rows
        b__a = Column.number()  # Show "a" from "b". This works for plain old objects too.
        # b = Column(bulk=True, show=False, )
        b = Column(
            bulk=True,
            show=False,
            filter_choices=Foo.objects.all()[:10],
            # The line above is short for: filter_field=forms.ChoiceField(choices=[('', '')] + [(x.pk, x) for x in Foo.objects.all()[:10]]),
            bulk_choices=Foo.objects.all()[:10],
            # bulk_field=forms.ChoiceField(choices=[('', '')] + [(x.pk, x) for x in Foo.objects.all()[:10]]),
        )
        c = Column(bulk=True)  # The form is created automatically
        # TODO: examples for filter_field, filter_type
        d = Column(display_name='Display name',
                   css_class='css_class',
                   url='url',
                   title='title',
                   sortable=False,
                   group='Foo',
                   filter=False,
                   auto_rowspan=True,
                   cell_value=lambda row: row.b.a // 3,
                   cell_format=lambda value: '- %s -' % value,
                   cell_attrs={
                       'class': lambda row: 'cj',
                       'title': 'cell title'},
                   cell_url='url',
                   cell_url_title='cell url title')
        e = Column(group='Foo', cell_value='explicit value', filter=False, sortable=False)
        f = Column(show=False, filter=False, sortable=False)
        g = Column(attr='c', filter=False, sortable=False)
        django_templates_for_cells = Column(filter=False, sortable=False, cell_template='kitchen_sink_cell_template.html')

    return render_table_to_response(request, BarTable(Bar.objects.all()), template_name='base.html', paginate_by=20)