Skip to main content

BTC Template Tables

Some classes for for describing tables with an auto-generated template.

Detailed documentation is in the “docs” directory.

Quick start

  1. Add “template_tables” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = (
          ...
          'template_tables',
      )
  2. Create table class:

    class MyTable(BaseTemplateTable):
    
        css_classes = ['template-tables', 'mdl-data-table', 'mdl-js-data-table']
        empty_table_text = 'Нет данных'
    
        def get_header_rows(self) -> List[TableRowType]:
            [TR([
                TH(''),
                MDLNonNumericTH('Уч.', ordering='section'),
                MDLNonNumericTH('Документ', ordering='invoices__unique_num'),
                MDLNonNumericTH('КПТП', ordering='process_map__unique_number'),
                MDLNonNumericTH('Артикул ДСЕ', ordering='invoices__product__vendor_code'),
                MDLNonNumericTH('Наименование', ordering='invoices__product__name'),
                TH('Кол-во (шт.)', ordering='invoices__product__count'),
                TH('Вес (кг)', ordering='invoices__product__weight'),
                MDLNonNumericTH('Место', ordering='invoices__product__storage__name'),
            ])]
    
        def get_body_row(self, index: int, data_item: Any) -> TableRowType:
            invoice = data_item.get_invoice()
            product = safety_get_attribute(invoice, 'product')
            invoice_unique_number = f'{invoice.get_document_type_display()}-{invoice.unique_num}' if invoice else None
    
            transition_btn = ARSimpleLink(
                icon=ARMaterialIcon('chevron_right'),
                css_classes=['table-transition-btn'],
                html_params=dict(href=reverse('dispatcher:task_details:selected-products', kwargs=dict(pk=data_item.pk)))
            )
    
            return TR([
                MDLNonNumericTD(transition_btn),
                MDLNonNumericTD(data_item.section),
                MDLNonNumericTD(invoice_unique_number),
                MDLNonNumericTD(safety_get_attribute(data_item, 'process_map')),
                MDLNonNumericTD(safety_get_attribute(product, 'vendor_code')),
                MDLNonNumericTD(safety_get_attribute(product, 'name')),
                TD(safety_get_attribute(product, 'count')),
                TD(safety_get_attribute(product, 'weight')),
                MDLNonNumericTD(safety_get_attribute(product, 'storage__name')),
            ])
  3. Define view - ListView or FilterView:

    class MyTableView(TemplateTableViewMixin, FilterView):
    
        model = MyModel
        filterset_class = MyTableFilter
        table_class = MyTable
        template_name = 'tables/template_table_base.html'
    
        def get_queryset(self):
            return super().get_queryset().get_pretty_qs()
    
    # For ordering and searching, the django-filter package is used.
    # Order filter:
    
    _base_task_table_searching_fields = [
        'section',
        'invoices__unique_num',
        'process_map__unique_number',
        'invoices__product__vendor_code',
        'invoices__product__name',
        'invoices__product__count',
        'invoices__product__weight',
        'invoices__product__storage__name'
    ]
    
    class MyTableFilter(FilterSet):
    
        ordering = OrderingFilter(
            fields=tuple(
                (field_name, field_name) for field_name in _base_task_table_searching_fields
            )
        )
  4. In template:

    <!--
    tables/template_table_base.html
    
    That example uses btc-flex-forms for filters rendering
    -->
    
    <div>
        <div>{{ filter.form.as_flex }}</div>
        <div>{{ table.render }}</div>
        <div>{{ pagination.render }}</div>
    </div>
    
    <!-- Note: To transform table to ajax-table just you simple js-handler for link click events -->

Example:

https://user-images.githubusercontent.com/33987296/74619321-2cd5ef80-5146-11ea-8e7b-28ddf929541d.png

Metadata

Release files for btc-template-tables 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for btc-template-tables 0.4.2
File Size Uploaded Provenance Actions
btc-template-tables-0.4.2.tar.gz 8.7 kB Without provenance Details for btc-template-tables-0.4.2.tar.gz

Release files / btc-template-tables-0.4.2.tar.gz

Download URL btc-template-tables-0.4.2.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c995030ca704438ddfd47199b8428e6056f8972a06e2a2456e4ba991da28cbce
BLAKE2b-256 checksum
How to use checksums
f91323f47b24ad5fe8e5e62c9379d7b90eca1f24409faba854fbfcb2ae4db0e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.5

Security for btc-template-tables 0.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page