예제 #1
0
def test_query_namespace_inject():
    class FooException(Exception):
        pass

    def post_validation(form):
        del form
        raise FooException()

    with pytest.raises(FooException):
        foo = Table(
            data=[],
            model=Foo,
            request=Struct(method='POST', POST={}, GET=Struct(urlencode=lambda: None)),
            columns=[Column(name='foo', query__show=True, query__gui__show=True)],
            query__gui__post_validation=post_validation)
        foo.prepare(foo.request)
예제 #2
0
파일: views.py 프로젝트: boxed/great_apis
 class Meta:
     model = Person
     columns = Table.columns_from_model(
         model=Person,
         column__id__show=lambda table, **_: table.request.user.
         is_staff,
         column__last_name__show=lambda table, **_: table.request.user.
         is_admin)
예제 #3
0
def test_from_model():
    t = Table.from_model(
        model=Foo, data=Foo.objects.all(), column__a__display_name="Some a", column__a__extra__stuff="Some stuff"
    )
    assert [x.name for x in t.columns] == ["id", "a", "b"]
    assert [x.name for x in t.columns if x.show] == ["a", "b"]
    t.prepare(RequestFactory().get("/"))
    assert "Some a" == t.bound_column_by_name["a"].display_name
    assert "Some stuff" == t.bound_column_by_name["a"].extra.stuff
예제 #4
0
def test_from_model():
    t = Table.from_model(
        model=Foo,
        data=Foo.objects.all(),
        column__a__display_name='Some a',
        column__a__extra__stuff='Some stuff',
    )
    assert [x.name for x in t.columns] == ['id', 'a', 'b']
    assert [x.name for x in t.columns if x.show] == ['a', 'b']
    t.prepare(RequestFactory().get("/"))
    assert 'Some a' == t.bound_column_by_name['a'].display_name
    assert 'Some stuff' == t.bound_column_by_name['a'].extra.stuff
예제 #5
0
def test_query_namespace_inject():
    class FooException(Exception):
        pass

    def post_validation(form):
        del form
        raise FooException()

    with pytest.raises(FooException):
        foo = Table(data=[],
                    model=Foo,
                    request=Struct(method='POST',
                                   POST={'-': '-'},
                                   GET=Struct(urlencode=lambda: None)),
                    columns=[
                        Column(name='foo',
                               query__show=True,
                               query__gui__show=True)
                    ],
                    query__gui__post_validation=post_validation)
        foo.prepare(foo.request)
예제 #6
0
def test_from_model():
    t = Table.from_model(
        model=Foo,
        data=Foo.objects.all(),
        column__a__display_name='Some a',
        column__a__extra__stuff='Some stuff',
    )
    assert [x.name for x in t.columns] == ['id', 'a', 'b']
    assert [x.name for x in t.columns if x.show] == ['a', 'b']
    t.prepare(RequestFactory().get("/"))
    assert 'Some a' == t.bound_column_by_name['a'].display_name
    assert 'Some stuff' == t.bound_column_by_name['a'].extra.stuff
예제 #7
0
def explicit_table():

    columns = [
        Column(name="foo"),
        Column.number(name="bar"),
    ]

    return Table(data=get_data(),
                 columns=columns,
                 attrs=lambda table: {
                     'class': 'listview',
                     'id': 'table_id'
                 })
예제 #8
0
def test_from_model():
    t = Table.from_model(data=Foo.objects.all(), model=Foo)
    assert [x.name for x in t.columns] == ['id', 'a', 'b']
    assert [x.name for x in t.columns if x.show] == ['a', 'b']