Some classes for for describing tables with an auto-generated template.
Project description
Some classes for for describing tables with an auto-generated template.
Detailed documentation is in the “docs” directory.
Quick start
Add “template_tables” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = ( ... 'template_tables', )
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')), ])
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 ) )
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:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file btc-template-tables-0.4.2.tar.gz
.
File metadata
- Download URL: btc-template-tables-0.4.2.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c995030ca704438ddfd47199b8428e6056f8972a06e2a2456e4ba991da28cbce |
|
MD5 | 9a98231870277d01e1f89b60a49c2d5d |
|
BLAKE2b-256 | f91323f47b24ad5fe8e5e62c9379d7b90eca1f24409faba854fbfcb2ae4db0e8 |