def view_context(request, context): return Table( title=f'Documents of context {context}', auto__rows=Document.objects.filter(context=context), auto__include=['name'], columns__name__cell__url=lambda row, **_: row.get_absolute_url(), row__attrs__class__unread=lambda row, **_: is_unread( user=request.user, identifier=row.get_unread_identifier()), )
def view_context_list(request): return Table( auto__model=Context, auto__include=['name'], columns__name__cell__url=lambda row, **_: row.get_absolute_url(), columns__name__cell__format=lambda value, row, **_: value if value != 'Private wiki' else f'Private wiki for {row.custom_data}', title='Wiki contexts', )
class MyPage(Page): t1 = Table( auto__model=T1, columns__foo=dict( filter__include=True, ), columns__bar=dict( filter__include=True, ), ) t2 = Table( auto__model=T2, columns__foo=dict( filter__include=True, ), columns__bar=dict( filter__include=True, ), )
def index(request, path=''): p = (Path(settings.ARCHIVE_PATH) / path).absolute() assert str(p).startswith(str(Path(settings.ARCHIVE_PATH).absolute())), 'Someone is trying to hack the site' if p.is_file(): return FileResponse(open(p, 'rb'), filename=p.name) rows = [ x for x in p.glob('*') if not x.name.startswith('.') ] if request.GET.get('gallery') is not None: images = [ x for x in rows if is_image(x) ] return Table.div( rows=sorted(images, key=lambda x: x.name.lower()), page_size=None, columns__name=Column(cell__format=lambda row, **_: mark_safe(f'<img src="{row.name}" style="max-width: 100%">')) ) return Table( columns=dict( icon=Column( display_name='', header__attrs__style__width='25px', attr=None, cell__format=lambda row, **_: mark_safe('<i class="far fa-folder"></i>') if row.is_dir() else '' ), name=Column( cell__url=lambda row, **_: f'{row.name}/' if row.is_dir() else row.name, ), ), page_size=None, rows=sorted(rows, key=lambda x: x.name.lower()), actions__gallery=Action(attrs__href='?gallery') )
class MyPage(Page): header = Fragment() some_form = Form(fields=Namespace(fisk=Field(), )) some_other_form = Form(fields=Namespace( fjomp=Field(), fisk=Field(), )) a_table = Table( model=TFoo, columns=Namespace( columns=Column(), fusk=Column(attr='b', filter__include=True), ), )
def all_column_sorts(request): selected_shortcuts = ShortcutSelectorForm().bind( request=request).fields.shortcut.value or [] type_specifics = Namespace( choice__choices=['Foo', 'Bar', 'Baz'], multi_choice__choices=['Foo', 'Bar', 'Baz'], ) return Page(parts=dict(header=Header('All sorts of columns'), form=ShortcutSelectorForm(), table=Table( columns={ f'column_of_type_{t}': dict( type_specifics.get(t, {}), call_target__attribute=t, ) for t in selected_shortcuts }, rows=[DummyRow(i) for i in range(10)], )))
def test_set_class_on_actions_container(): t = Table() style_data = Namespace(actions__attrs__class={'object-tools': True}, ) reinvoke_new_defaults(t, style_data)
def table_auto_example_2(request): return Table( auto__model=Foo, rows=lambda table, **_: Foo.objects.all(), )
def table_auto_example_1(request): return Table(auto__model=Foo, )
cell__value=None, cell__template='kitchen_sink_cell_template.html', group='Bar', ) class Meta: title = 'Kitchen sink' _name = 'bar' page_size = 20 return BarTable(rows=TBar.objects.all()) example_6_view = Table(auto__model=TFoo, columns__a__bulk__include=True, bulk__actions__delete__include=True, extra_evaluated__report_name='example_download', columns__a__extra_evaluated__report_name='A').as_view() example_6_view = example('Table expressed directly as a view function')( example_6_view) @example(gettext('Two tables on the same page')) def table_two(request): return Page(parts__table_1=Table( auto__model=Foo, columns__a__filter__include=True, page_size=5, ), parts__table_2=Table(
def rooms(request): return Table( auto__model=Room, columns__name__cell__url=lambda row, **_: row.get_absolute_url(), )
def view_project_list(request): return Table( auto__model=Project, auto__include=['name'], columns__name__cell__url=lambda row, **_: row.get_absolute_url(), actions__create_project__attrs__href='create/')
def table_two(request): return Page(parts__table_1=Table(auto__model=Foo, columns__a__filter__include=True), parts__table_2=Table(auto__model=TBar, columns__b__filter__include=True))
def index(request): return Table(auto__model=Item)
Role, MetaDataObject, ) from dh.views import ( actor, show, index, metadata_object, role, search, ) urlpatterns = [ path('', index), path('search/', search), path('actors/', Table(auto__model=Actor).as_view()), path('actors/<int:pk>/', actor), path('shows/', Table(auto__model=Show).as_view()), path('shows/<int:pk>/', show), path('shows/not-parsed/', Table( auto__rows=Show.objects.filter(successful_parse=False), columns__name__cell__url=lambda row, **_: row.get_absolute_url(), ).as_view()), path('roles/', Table(auto__model=Role).as_view()), path('roles/<int:pk>/', role), path('metadata/', Table( auto__model=MetaDataObject, columns__name__cell__url=lambda row, **_: row.get_absolute_url(), columns__name__filter__include=True, columns__name__filter__freetext=True, ).as_view()),
class BusyPage(Page): tfoo = Table(auto__model=TFoo, page_size=5, columns__name__filter=dict(include=True, field__include=True)) tbar = Table(auto__model=TBar, page_size=5, columns__b__filter=dict(include=True, field__include=True)) create_tbar = Form.create(auto__model=TBar)