Example #1
0
File: debug.py Project: tltx/iommi
    class TreeTable(Table):
        class Meta:
            template = Template("""
                <style>
                    .full-path {
                        opacity: 0.0;
                    }
                    tr:hover .full-path {
                        opacity: 0.6;
                    }
                    
                    tr {
                        opacity: 0.4;
                    }
                    tr.included {
                        opacity: 1;
                    }
                    
                </style>
                
                {% include "iommi/table/table.html" %}            
            """)
            sortable = False
            row__attrs__class__included = (lambda row, **_: row.included)
            page_size = None

        dunder_path = Column(
            cell__value=lambda row, **_: row.dunder_path,
            cell__format=dunder_path__format,
        )
        path = Column()
        type = Column(
            cell__url=lambda row, **_: f'https://docs.iommi.rocks/en/latest/{row.base_type}.html' if row.base_type else None
        )
        included = Column.boolean()
Example #2
0
 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
Example #3
0
class EntryAdminTable(EntryTable):
    edit = Column.edit()
    delete = Column.delete()

    class Meta:
        actions = dict(
            create=Action.button(tag='a', attrs__href='create'),
            logout=Action.button(tag='a', attrs__href='/logout/'),
        )
Example #4
0
 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.
         filter__include=True,  # put this field into the query language
     )
     c = Column(
         bulk__include=True,  # Enable bulk editing for this field
         filter__include=True,
     )
Example #5
0
class IndexPage(Page):
    title = html.h1("TMDB")
    welcome_text = "Welcome to my TMDB!"

    actors = Table(
        auto__model=Actor,
        page_size=5,
        columns__name=Column(
            cell__value=lambda row, **_: f"{row.last_name} {row.first_name}",
        ),
        columns__created__include=False,
        columns__modified__include=False,
        columns__first_name__include=False,
        columns__last_name__include=False,
        columns__countries__cell__format=lambda row, **_: mark_safe("".join(
            format_html(
                f'<a href="{country.get_absolute_url()}">{country}</a><br>')
            for country in row.countries.all())),
    )
    movies = Table(
        auto__model=Movie,
        page_size=5,
        columns__created__include=False,
        columns__modified__include=False,
        columns__actors__cell__format=lambda row, **_: mark_safe("".join(
            format_html(f'<a href="{actor.get_absolute_url()}">{actor}</a><br>'
                        ) for actor in row.actors.all())),
        columns__directors__cell__format=lambda row, **_: mark_safe("".join(
            format_html(
                f'<a href="{director.get_absolute_url()}">{director}</a><br>')
            for director in row.directors.all())),
        columns__countries__cell__format=lambda row, **_: mark_safe("".join(
            format_html(
                f'<a href="{country.get_absolute_url()}">{country}</a><br>')
            for country in row.countries.all())),
        columns__categories__cell__format=lambda row, **_: mark_safe("".join(
            format_html(
                f'<a href="{category.get_absolute_url()}">{category}</a><br>')
            for category in row.categories.all())),
    )
    directors = Table(
        auto__model=Director,
        page_size=5,
        columns__name=Column(
            cell__value=lambda row, **_: f"{row.last_name} {row.first_name}",
        ),
        columns__created__include=False,
        columns__modified__include=False,
        columns__first_name__include=False,
        columns__last_name__include=False,
        columns__countries__cell__format=lambda row, **_: mark_safe("".join(
            format_html(
                f'<a href="{country.get_absolute_url()}">{country}</a><br>')
            for country in row.countries.all())),
    )
Example #6
0
 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),
         ),
     )
Example #7
0
 class Meta:
     auto__model = Album
     page_size = 20
     columns__name__cell__url = lambda row, **_: row.get_absolute_url()
     columns__name__filter__include = True
     columns__year__filter__include = True
     columns__year__filter__field__include = False
     columns__artist__filter__include = True
     columns__edit = Column.edit(
         include=lambda request, **_: request.user.is_staff,
     )
     columns__delete = Column.delete(
         include=lambda request, **_: request.user.is_staff,
     )
     actions__create_album = Action(attrs__href='/albums/create/',
                                    display_name=_('Create album'))
Example #8
0
File: views.py Project: boxed/forum
 class Meta:
     title = None
     auto__model = Message
     auto__exclude = ['path']
     rows = room__rows
     columns__unread_from_here_href = Column(attr=None, cell__value=room__unread_from_here_href)
     # Keep backwards compatibility with old (super unsafe!) forum, but use safe markdown for new messages
     columns__text__cell__format = lambda value, row, **_: pre_format(value) if row.time_created.year > 2015 else pre_format_legacy(value)
     columns__text__cell__tag = None
     preprocess_rows = room__preprocess_rows
     header__template = Template('')
     row__template = get_template('forum/message.html')
     row__attrs__class = dict(
         indent_0=lambda row, **_: row.indent == 0,
         message=True,
         current_user=lambda table, row, **_: table.get_request().user == row.user,
         other_user=lambda table, row, **_: table.get_request().user != row.user,
         unread=lambda row, unread_data, **_: unread_data.is_unread(row.last_changed_time),
         unread2=lambda row, unread_data, **_: unread_data.is_unread2(row.last_changed_time),
     )
     attrs = dict(
         cellpadding='0',
         cellspacing='0',
         id='first_newtable',
         align='center',
         class__roomtable=True,
     )
     paginator = dict(
         min_page_size=10,
         template='forum/room-footer.html',
         page=room__get_start_page,
         show_always=True,
     )
     page_size = PAGE_SIZE
Example #9
0
    class TestTable(Table):
        foo = Column(header__attrs__title="Some title")

        class Meta:
            sortable = False
            actions = dict(
                a=Action(display_name='Foo',
                         attrs__href='/foo/',
                         include=lambda table, **_: table.rows is not rows),
                b=Action(display_name='Bar',
                         attrs__href='/bar/',
                         include=lambda table, **_: table.rows is rows),
                c=Action(display_name='Baz',
                         attrs__href='/bar/',
                         group='Other'),
                d=dict(display_name='Qux', attrs__href='/bar/', group='Other'),
                e=Action.icon('icon_foo',
                              display_name='Icon foo',
                              attrs__href='/icon_foo/'),
                f=Action.icon('icon_bar',
                              icon_classes=['lg'],
                              display_name='Icon bar',
                              attrs__href='/icon_bar/'),
                g=Action.icon('icon_baz',
                              icon_classes=['one', 'two'],
                              display_name='Icon baz',
                              attrs__href='/icon_baz/'),
            )
Example #10
0
    class FooTable(Table):
        # I can add checkboxes to each row
        s = Column.select()
        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

        class Meta:
            page_size = 3
            # And register a button that will get the selection passed in its post_handler
            bulk__actions__print = Action.primary(
                display_name='print me',
                post_handler=bulk__actions__print__post_handler)
Example #11
0
File: views.py Project: boxed/forum
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')
    )
Example #12
0
    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.from_model(
            model=TBar,
            model_field_name='b',
            bulk__include=True,
            filter__include=True,
        )
        c = Column(bulk__include=True)  # The form is created automatically

        d = Column(
            display_name='Display name',
            attr__class__css_class=True,
            header__url='https://docs.iommi.rocks',
            sortable=False,
            group='Foo',
            auto_rowspan=True,
            filter__include=True,
            cell__value=lambda row, **_: row.b.a // 3,
            cell__format=lambda value, **_: '- %s -' % value,
            cell__attrs__class={'text-center': True},
            cell__attrs__title='cell title',
            cell__url='url',
            cell__url_title='cell url title',
        )
        e = Column(group='Foo', cell__value='explicit value', sortable=False)
        f = Column(include=False, sortable=False)
        g = Column(attr='c', sortable=False)
        django_templates_for_cells = Column(
            sortable=False,
            cell__value=None,
            cell__template='kitchen_sink_cell_template.html',
            group='Bar',
        )

        class Meta:
            title = 'Kitchen sink'
            _name = 'bar'
            page_size = 20
Example #13
0
class EntryUnapproveTable(EntryTable):
    select = Column.select()

    class Meta:
        title = 'Approved entries'
        bulk__title = None

        @staticmethod
        def rows(table, **_):
            return Entry.objects.filter(approver=table.get_request().user)

        bulk__actions__submit = dict(
            include=True,
            attrs__value='Unapprove',
        )

        @staticmethod
        def bulk__actions__submit__post_handler(table, **_):
            table.bulk_queryset().update(approver=None)
Example #14
0
    class MyTable(Table):
        class Meta:
            iommi_style = 'my_style'
            model = Foo

        bar = Column(bulk__include=True)
Example #15
0
 class FooTable(Table):
     name = Column(filter__include=True)
Example #16
0
 class Meta:
     parts__list_shortner_entry__columns__short = Column(
         cell__url=lambda value, **_: f'/s/{value}',
         after=0,
     )