Пример #1
0
def view_transactions(request):
    # TODO: bulk edit on description field should be append, not set
    return render_table_to_response(
        request=request,
        table=TransactionTable(data=Transaction.objects.filter(user=request.user)),
        template_name="money/view_transaction_list.html",
    )
Пример #2
0
def view_transactions(request):
    # TODO: bulk edit on description field should be append, not set
    return render_table_to_response(
        request=request,
        table=TransactionTable(data=Transaction.objects.filter(
            user=request.user)),
        template_name='money/view_transaction_list.html')
Пример #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 table, column, row, value: value[-1]
                   )  # Display the last value of the tuple
        sum_c = Column(cell__value=lambda table, column, 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(data=foos),
                                    template_name='base.html')
Пример #4
0
def example4(request):
    request.user.is_admin = True
    request.user.is_staff = True
    return render_table_to_response(
        request,
        table__data=Person.objects.all(),
        table__column__id__show=lambda table, **_: table.request.user.is_staff,
        table__column__last_name__show=lambda table, **_: table.request.user.is_admin)
Пример #5
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=data))
    assert isinstance(response, HttpResponse)
    assert '<table' in response.content
Пример #6
0
def example4(request):
    request.user.is_admin = True
    request.user.is_staff = True
    return render_table_to_response(
        request,
        table__data=Person.objects.all(),
        table__column__id__show=lambda table, **_: table.request.user.is_staff,
        table__column__last_name__show=lambda table, **_: table.request.user.
        is_admin)
Пример #7
0
def view_project_list(request):
    return render_table_to_response(
        request=request,
        table__data=Project.objects.all().order_by('name'),
        table__column__name__cell__url=lambda row, **_: row.get_absolute_url(),
        table__include=['name'],
        context=dict(title='Projects'),
        template='wiki/list.html',  # TODO: Fix when tri.table has base_template
    )
Пример #8
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=data))
    assert isinstance(response, HttpResponse)
    assert b'<table' in response.content
Пример #9
0
def view_project(request, project_name):
    project = Project.objects.get(name=project_name)
    return render_table_to_response(
        request=request,
        table__data=Issue.objects.filter(project=project).order_by('pk'),
        table__column__name__cell__url=lambda row, **_: row.get_absolute_url(),
        table__include=['name'],
        context=dict(title=f'Issues for {project}'),
        template='wiki/list.html',  # TODO: Fix when tri.table has base_template
    )
Пример #10
0
def view_context_list(request):
    return render_table_to_response(
        request=request,
        table__data=Context.objects.all().order_by('name'),
        table__column__name__cell__url=lambda row, **_: row.get_absolute_url(),
        table__column__name__cell__format=lambda value, row, **_: value
        if value != 'Private wiki' else f'Private wiki for {row.custom_data}',
        table__include=['name'],
        context=dict(title='Wiki contexts'),
        template='wiki/list.html',  # TODO: Fix when tri.table has base_template
    )
Пример #11
0
def list_model(request, app_name, model_name, app, **kwargs):
    kwargs = setdefaults_path(
        kwargs,
        table__data=apps.all_models[app_name][model_name].objects.all(),
        table__extra_fields=[Column.edit(after=0, cell__url=lambda row, **_: '%s/edit/' % row.pk)],
    )
    return render_table_to_response(
        request,
        template='base.html',
        links=[Link(title='Create %s' % model_name.replace('_', ' '), url='create/')],
        **kwargs
    )
Пример #12
0
def example5(request):
    class PersonTable(Table):
        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)

    request.user.is_admin = True
    request.user.is_staff = True
    return render_table_to_response(request, table=PersonTable())
Пример #13
0
def view_context(request, context_name):
    return render_table_to_response(
        request=request,
        table__data=Document.objects.filter(
            context__name__iexact=context_name).order_by('pk'),
        table__column__name__cell__url=lambda row, **_: row.get_absolute_url(),
        table__include=['name'],
        context=dict(
            title=
            f'Documents of context {Context.objects.get(name__iexact=context_name)}'
        ),
        template='wiki/list.html',  # TODO: Fix when tri.table has base_template
    )
Пример #14
0
def view_version_list(request, context_name, document_name):
    doc = Document.objects.get(context__name__iexact=context_name,
                               name__iexact=document_name)
    return render_table_to_response(
        request=request,
        context=dict(title=f'Versions of {doc}', ),
        table__data=DocumentVersion.objects.filter(
            document=doc).order_by('version'),
        table__include=['name', 'version', 'changed_time'],
        table__column__version__cell__url=lambda row, **_: row.
        get_absolute_url(),
        template='wiki/list.html',  # TODO: Fix when tri.table has base_template
    )
Пример #15
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.
            query__show=True,  # put this field into the query language
            query__gui__show=True)  # put this field into the simple filtering GUI
        c = Column(
            bulk__show=True,  # Enable bulk editing for this field
            query__show=True,
            query__gui__show=True)

    return render_table_to_response(request, BarTable(data=Bar.objects.all()), template_name='base.html', paginate_by=20)
Пример #16
0
def example5(request):
    class PersonTable(Table):
        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)

    request.user.is_admin = True
    request.user.is_staff = True
    return render_table_to_response(request, table=PersonTable())
Пример #17
0
def list(request, model, title):
    return render_table_to_response(
        request=request,
        table__model=model,
        table__column__name__cell__url=lambda row, **_: f'{row.pk}/',
        table__extra_fields=[
            Column.edit(after=0, cell__url=lambda row, **_: f'{row.pk}/edit/'),
            Column.delete(after=0,
                          cell__url=lambda row, **_: f'{row.pk}/delete/'),
        ],
        template='wiki/list.html',
        context=dict(title=evaluate(title, model=model), ),
        links=[
            Link(f'Create {model._meta.verbose_name}', attrs__href='create/')
        ])
Пример #18
0
def index(request):
    try:
        last_transaction = Transaction.objects.filter(user=request.user, virtual=False).order_by("-time")[0]
    except (Transaction.DoesNotExist, IndexError):
        last_transaction = None
    return render_table_to_response(
        request=request,
        table=TransactionTable(data=Transaction.objects.filter(user=request.user).filter(category=None)),
        template_name="money/index.html",
        context={
            "matched_count": Transaction.objects.filter(user=request.user, category__isnull=False).count(),
            "unmatched_count": Transaction.objects.filter(user=request.user, category__isnull=True).count(),
            "last_transaction": last_transaction,
            "categories": Category.objects.filter(user=request.user),
        },
    )
Пример #19
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.choice_queryset(
            show=False,
            choices=Foo.objects.all(),
            model=Foo,
            bulk__show=True,
            query__show=True,
            query__gui__show=True,
        )
        c = Column(bulk=True)  # The form is created automatically

        d = Column(
            display_name='Display name',
            css_class={'css_class'},
            url='url',
            title='title',
            sortable=False,
            group='Foo',
            auto_rowspan=True,
            cell__value=lambda table, column, row: row.b.a // 3,
            cell__format=lambda table, column, row, value: '- %s -' % value,
            cell__attrs__class__cj=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(show=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')

        class Meta:
            model = Bar

    return render_table_to_response(request,
                                    BarTable(data=Bar.objects.all()),
                                    template_name='base.html',
                                    paginate_by=20)
Пример #20
0
def list_model(request, app_name, model_name, app, **kwargs):
    kwargs = setdefaults_path(
        kwargs,
        table__data=apps.all_models[app_name][model_name].objects.all(),
        table__extra_fields=[
            Column.edit(after=0,
                        cell__url=lambda row, **_: '%s/edit/' % row.pk)
        ],
    )
    return render_table_to_response(request,
                                    template='base.html',
                                    links=[
                                        Link(title='Create %s' %
                                             model_name.replace('_', ' '),
                                             url='create/')
                                    ],
                                    **kwargs)
Пример #21
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.
            query__show=True,  # put this field into the query language
            query__gui__show=True
        )  # put this field into the simple filtering GUI
        c = Column(
            bulk__show=True,  # Enable bulk editing for this field
            query__show=True,
            query__gui__show=True)

    return render_table_to_response(request,
                                    BarTable(data=Bar.objects.all()),
                                    template_name='base.html',
                                    paginate_by=20)
Пример #22
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 table, column, row, value, **_: value[-1])  # Display the last value of the tuple
        sum_c = Column(cell__value=lambda table, column, 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(data=foos), template_name='base.html')
Пример #23
0
def all_models(request, app, **kwargs):
    def data():
        for app_name, models in apps.all_models.items():
            for name, cls in models.items():
                if app.get(app_name, {}).get(name, {}).get('show', True):
                    yield Struct(app_name=app_name, model_name=name, model=cls)

    class ModelsTable(Table):
        app_name = Column(auto_rowspan=True)
        model_name = Column(cell__url=lambda row, **_: '/triadmin/%s/%s/' % (row.app_name, row.model_name))

        class Meta:
            sortable = False

    result = render_table_to_response(
        request,
        template='base.html',
        table=ModelsTable(data=data()),
        paginate_by=None,
        **kwargs)
    return result
Пример #24
0
def all_models(request, app, **kwargs):
    def data():
        for app_name, models in apps.all_models.items():
            for name, cls in models.items():
                if app.get(app_name, {}).get(name, {}).get('show', True):
                    yield Struct(app_name=app_name, model_name=name, model=cls)

    class ModelsTable(Table):
        app_name = Column(auto_rowspan=True)
        model_name = Column(cell__url=lambda row, **_: '/triadmin/%s/%s/' %
                            (row.app_name, row.model_name))

        class Meta:
            sortable = False

    result = render_table_to_response(request,
                                      template='base.html',
                                      table=ModelsTable(data=data()),
                                      paginate_by=None,
                                      **kwargs)
    return result
Пример #25
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.choice_queryset(
            show=False,
            choices=Foo.objects.all()[:10],
            model=Foo,
            bulk__show=True,
            query__show=True,
            query__gui__show=True,
        )
        c = Column(bulk=True)  # The form is created automatically

        d = Column(display_name='Display name',
                   css_class={'css_class'},
                   url='url',
                   title='title',
                   sortable=False,
                   group='Foo',
                   auto_rowspan=True,
                   cell__value=lambda table, column, row: row.b.a // 3,
                   cell__format=lambda table, column, row, value: '- %s -' % value,
                   cell__attrs={
                       'class': lambda table, column, row: 'cj',
                       'title': 'cell title'},
                   cell__url='url',
                   cell__url_title='cell url title')
        e = Column(group='Foo', cell__value='explicit value', sortable=False)
        f = Column(show=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')

        class Meta:
            model = Bar

    return render_table_to_response(request, BarTable(data=Bar.objects.all()), template_name='base.html', paginate_by=20)
Пример #26
0
def index(request):
    try:
        last_transaction = Transaction.objects.filter(
            user=request.user, virtual=False).order_by('-time')[0]
    except (Transaction.DoesNotExist, IndexError):
        last_transaction = None
    return render_table_to_response(
        request=request,
        table=TransactionTable(data=Transaction.objects.filter(
            user=request.user).filter(category=None)),
        template_name='money/index.html',
        context={
            'matched_count':
            Transaction.objects.filter(user=request.user,
                                       category__isnull=False).count(),
            'unmatched_count':
            Transaction.objects.filter(user=request.user,
                                       category__isnull=True).count(),
            'last_transaction':
            last_transaction,
            'categories':
            Category.objects.filter(user=request.user),
        })
Пример #27
0
def example1(request):
    return render_table_to_response(
        request,
        table__data=Person.objects.all())
Пример #28
0
def example2(request):
    return render_table_to_response(
        request,
        table__data=Person.objects.all(),
        table__column__id__show=True)
Пример #29
0
def rooms(request):
    return render_table_to_response(request, table__model=Room)
Пример #30
0
def example3(request):
    return render_table_to_response(
        request,
        table__data=Person.objects.all(),
        table__column__last_name__cell__format=lambda value, **_: mark_safe('<h1>hello %s!</h1>' % value))
Пример #31
0
def example1(request):
    return render_table_to_response(request, table__data=Person.objects.all())
Пример #32
0
def example2(request):
    return render_table_to_response(request,
                                    table__data=Person.objects.all(),
                                    table__column__id__show=True)
Пример #33
0
def example3(request):
    return render_table_to_response(
        request,
        table__data=Person.objects.all(),
        table__column__last_name__cell__format=lambda value, **_: mark_safe(
            '<h1>hello %s!</h1>' % value))