Package: tri.table
Warningtri.table is end of life. It has been merged intoiommi.iommi is backwards incompatible but the porting effort should be fairly mild,
the biggest changes are thatshowis now calledinclude, tri.query’sVariableis renamed toFilterand plural is used consistently for
containers (socolumn__fooiscolumns__fooin iommi).tri.tabletri.table is a library to make full featured HTML tables easily:generates header, rows and cellsgrouping of headersfilteringsortingbulk editpaginationautomatic rowspanlink creationcustomization on multiple levels, all the way down to templates for cellsAll these examples and a bigger example using many more features can be found in the examples django project.Read the full documentation for more.Contentstri.tableSimple exampleFancy django featuresUsageMotivationRunning testsLicenseDocumentationChangelog8.5.1 (2020-12-04)8.5.0 (2020-08-21)8.4.0 (2020-04-24)8.3.0 (2020-01-09)8.2.0 (2019-11-21)8.1.1 (2019-10-23)8.1.0 (2019-10-15)8.0.0 (2019-06-14)7.0.2 (2019-05-06)7.0.1 (2019-05-03)7.0.0 (2019-04-12)6.3.0 (2019-03-15)6.2.1 (2019-03-05)6.2.0 (2019-03-04)6.1.0 (2019-01-29)6.0.3 (2018-12-06)6.0.2 (2018-12-06)6.0.1 (2018-12-04)6.0.0 (2018-12-03)5.3.1 (2018-10-10)5.3.0 (2018-08-19)5.2.2 (2018-06-29)5.2.1 (2018-06-18)5.2.0 (2018-06-15)5.1.1 (2018-04-09)5.1.0 (2018-01-08)5.0.0 (2017-08-22)4.3.1 (2017-05-31)4.3.0 (2017-04-25)4.2.0 (2017-04-21)4.1.2 (2017-04-19)4.1.1 (2017-04-10)4.1.0 (2017-03-22)4.0.0 (2016-09-15)3.0.1 (2016-09-06)3.0.0 (2016-09-02)2.5.0 (2016-07-14)2.4.0 (2016-07-13)2.3.0 (2016-07-12)2.2.0 (2016-06-23)2.1.0 (2016-06-16)2.0.0 (2016-06-02)1.16.0 (2016-04-25)1.15.0 (2016-04-21)1.14.0 (2016-04-19)1.13.0 (2016-04-08)1.12.0 (2016-02-29)1.11.0 (2016-02-04)1.10.0 (2016-01-28)1.9.0 (2016-01-19)Simple exampledefreadme_example_1(request):# Say I have a class...classFoo(object):def__init__(self,i):self.a=iself.b='foo%s'%(i%3)self.c=(i,1,2,3,4)# and a list of themfoos=[Foo(i)foriinxrange(4)]# I can declare a table:classFooTable(Table):a=Column.number()# This is a shortcut that results in the css class "rj" (for right justified) being added to the header and cellb=Column()c=Column(cell__format=lambdatable,column,row,value,**_:value[-1])# Display the last value of the tuplesum_c=Column(cell__value=lambdatable,column,row,**_:sum(row.c),sortable=False)# Calculate a value not present in Foo# now to get an HTML table:returnrender_table_to_response(request,FooTable(data=foos),template='base.html')And this is what you get:Fancy django featuresSay I have some models:classFoo(models.Model):a=models.IntegerField()def__unicode__(self):return'Foo:%s'%self.aclassBar(models.Model):b=models.ForeignKey(Foo)c=models.CharField(max_length=255)Now I can display a list of Bars in a table like this:defreadme_example_2(request):fill_dummy_data()classBarTable(Table):select=Column.select()# Shortcut for creating checkboxes to select rowsb__a=Column.number(# Show "a" from "b". This works for plain old objects too.query__show=True,# put this field into the query languagequery__gui__show=True)# put this field into the simple filtering GUIc=Column(bulk=True,# Enable bulk editing for this fieldquery_show=True,query__gui__show=True)returnrender_table_to_response(request,BarTable(data=Bar.objects.all()),template='base.html',paginate_by=20)This gives me a view with filtering, sorting, bulk edit and pagination.All these examples and a bigger example using many more features can be found in the examples django project.Read the full documentation for more.UsageAdd tri_form, tri_query, tri_table to INSTALLED_APPS.Motivationtri.table grew out of a frustration with how tables were created at TriOptima. We have a /lot/ of tables and the code to produce them included long HTML templates and often the code to extract and massage the data in some trivial way ended up as methods on the model classes or template tags, even though it was only used by one view.This code was also error prone to change since we often have columns that we show or hide based on the permissions of the user, which meant thetheadandtbodyhad to be in sync. When you have a lot of columns and more and more complex logic for when to show/hide columns this can become harder than it sounds!We also saw that almost always the names of the columns (aka the headers) could be derived from the name of the field they should display data for, so we opted for defaults to make this case easier.It was very important for us to have customization available at many levels. Many table libraries have really nice and short code for the default case but when you have to customize some tiny thing you have to rewrite huge swaths of the library’s code. We didn’t want to do that since we made this library in order to refactor out exactly this thing from our existing code base. We ended up with the powerful pattern of being able to supply callables for the points of customization, leading to small tweaks moving into the table definition instead of being scattered in model or template tag code. We also have many levels or customization so that the path from “just display columns x, y and z somehow” to heavy customization is smooth and gradual.We chose to mimic how django forms and models are declared because we really like that kind of declarative style, but you can also use it in a more functional style if you want. The latter is useful when you want to create a list of the columns to display programmatically for example.This library has been a big win for us. The time to create a page with a table on it has been drastically reduced without sacrificing any flexibility when we later want to tweak the view.Running testsYou need tox installed then justmake test.LicenseBSDDocumentationhttps://tritable.readthedocs.org.Changelog8.5.1 (2020-12-04)Removed broken validation of sort columns. This validation prevented sorting on annotations which was very confusing as it worked in dev.NOTE: tri.table is a legacy library and is fully replaced by iommi8.5.0 (2020-08-21)Include tri.struct 4.x as possible requirement8.4.0 (2020-04-24)Fix bulk form missing requests attribute. (Failing on ajax selects)Upped dependency tri.declarative to 5.x8.3.0 (2020-01-09)Change python version to 3.78.2.0 (2019-11-21)Introduceddata_retrivial_method, and turned it on by default forforeign_keyandmany_to_many. This means that by default tables are now efficient instead of requiring you to useprefetch_relatedorselect_relatedmanually.Added missingUUIDFieldfactoryAdded missingColumn.multi_choicepage_sizewasn’t refinable8.1.1 (2019-10-23)Upped dependency on tri.form due to a bug fix there, and the use of that bug fix in tri.tableHandle late binding ofrequestmember ofTableRemoved deprecated use of@creation_ordered8.1.0 (2019-10-15)ImplementedTable.actionsas a replacement forrender_table`s argument `links.Column.multi_choice_querysetwas broken.Fixedmany_to_manyshortcut.Deprecated the following parameters torender_table:template: replaced byTable.templatepaginate_by: replaced byTable.page_sizeshow_hits: no replacementhit_label: no replacementpage: no replacementblank_on_empty: no replacementlinks: replaced byTable.actionsBumped dependency tri.declarative to 4.x8.0.0 (2019-06-14)Renamed module fromtri.tabletotri_tableDropped support for python2 and Django < 2.07.0.2 (2019-05-06)Fixed cases where from_model lost the type when inheriting7.0.1 (2019-05-03)Fixed a bug where columns that had query or bulk but attr=None would crash7.0.0 (2019-04-12)MakeColumnshortcuts compatible with subclassing. The previous fix didn’t work all the way.Use the new major tri.declarative, and update to follow the new style of class member shortcutsRemoved support for django 1.8bulk_querysetis now usable to create your own bulk actions without usingTable.bulk_formBulk form now auto creates viaForm.from_modelcorrectlyQuery is now auto created viaQuery.from_modelcorrectly6.3.0 (2019-03-15)Make Column shortcuts compatible with subclassing6.2.1 (2019-03-05)Fixed a crash when you used a custom paginator in django 2.0+6.2.0 (2019-03-04)Fixes for jinja2 compatibility (still not fully working)preprocess_datanow takes a new keyword argumenttableYou can now get the paginator context itself viaTable.paginator_contextPaginator template is configurableFixed a bug where we triggered our own deprecation warning forColumnUse the new paginator API for django 2.0+6.1.0 (2019-01-29)DeprecatedColumnargumentattrsin favor ofheader__attrsAdded CSS classesascending/descendingon headersAdded ability to customize superheaders viaColumn.superheaderAdded ability to customizeColumnheader template viaheader__templateDeprecatedtitleparameter toColumnDeprecatedcss_classparameter toColumnRemoved class=’row{1,2}’ from <tr> tags. This is better accomplished with CSS.6.0.3 (2018-12-06)Bug fix: “Select all” header button should fire click event, not just toggle the state.6.0.2 (2018-12-06)Bug fix: “Select all items” question hidden when select all clicked again.Bug fix: only show “Select all item” question if a paginator is present.6.0.1 (2018-12-04)Bug fix: “Select all items” question should only be presented once.6.0.0 (2018-12-03)Removed argumentpkstopost_bulk_edit. This argument is incompatible with non-paginated bulk edit, and it’s redundant with thequerysetargument.Added support for bulk editing of an entire queryset, not just the selected items on the current page.Fixed bug where the template context was not carried over to the row rendering when using a custom row template.Removedpaginatortemplate tag, moved the functionality intoTable.render_paginator. This means it can be used from jinja2 and is generally easier to work with.Avoid filtering with tri.query if not needed. This means you can now take a slice of a queryset before you pass it to tri.table, if and only if you don’t then have filters to apply.New feature: refinable attributepreprocess_dataonTable. This is useful if you want to for example display more than one row per result of a queryset or convert the paginated data into a list and do some batch mutation on the items.preprocess_rowreturning None is now deprecated. You should now return the row. Just returning the object you were sent is probably what you want.5.3.1 (2018-10-10)AddedColumn.boolean_tristatefor optionally filter boolean fields.Add support for setting namespace on tables to be able to reuse column names between two tables in the same view.Removed buggy use ofsetdefaults. This could cause overriding of nested arguments to not take.5.3.0 (2018-08-19)Addedpreprocess_rowfeature. You can use it to mutate a row in place before access.MadeTableaRefinableObject5.2.2 (2018-06-29)Fix bad mark_safe invocation on custom cell format output.5.2.1 (2018-06-18)Fixed bug with backwards compatibility forLink.5.2.0 (2018-06-15)New feature: default sort ordering. Just passdefault_sort_ordertoTable.Linkclass is now just inherited from tri_formLink. Introduced a deprecation warning for the constructor argumenturl.Simplifiedpreparehandling forTable. You should no longer need to care about this for most operations. You will still need to callprepareto trigger the parsing of URL parameters for sorting etc.Fixed many_to_many_factory5.1.1 (2018-04-09)Lazy and memoized BoundCell.value5.1.0 (2018-01-08)Fix sorting of columns that contains None, this was not working in Python 35.0.0 (2017-08-22)Moved to tri.declarative 0.35, tri.form 5.0 and tri.query 4.0. Check release notes for tri.form and tri.query for backwards incompatible changesRemoved deprecatedtemplate_nameparameter torender_tableNote thatfoo__classto specify a constructor/callable is no longer a valid parameter, because of updated tri.form, usefoo__call_targetor justfoo4.3.1 (2017-05-31)Bugfix: sorting on reverse relations didn’t work4.3.0 (2017-04-25)Bugfix for Django 1.10 template handlingUpdated to tri.form 4.7.1Moved bulk button inside the table tagDropped support for Django 1.74.2.0 (2017-04-21)New feature: post bulk edit callback4.1.2 (2017-04-19)Fixed silly non-ascii characters in README.rst and also changed to survive silly non-ascii characters in that same file.4.1.1 (2017-04-10)Fix missing copy ofattrs__class4.1.0 (2017-03-22)Columnclass now inherits fromobject, making the implementation more pythonic.
(Attributes still possible to override in constructor call, seeNamespaceAwareObject)*.templateoverrides can now be specified asdjango.template.Templateinstances.Thetemplate_nameparameter torender_tableis now deprecated and superceeded by atemplateparameter.4.0.0 (2016-09-15)Updated to newest tri.form, tri.query, tri.declarative. This gives us simpler factories forfrom_modelmethods.Added shortcuts toColumn:timeanddecimalThe following shortcuts have been updated to use the correspondingVariableshortcuts: date, datetime and emailFix failure in endpoint result return on empty payload.[]is a valid endpoint dispatch result.render_table/render_table_to_responseno longer allow table to be passed as a positional argument3.0.1 (2016-09-06)Fix crash on unidentified sort parameter.3.0.0 (2016-09-02)bound_rowis passed to row level callables. This is a potential breaking
change if you didn’t do**_at the end of your function signatures (which you
should!)bound_rowandbound_columnis passed to cell level callables. This is a
potential breaking change like above.BoundRownow supportsextra.compatibible with Django 1.9 & 1.10Added strict check on the kwargs config namespace ofTableAddedextranamespace toTableAddedbound_cellparameter to rendering of cell templates.2.5.0 (2016-07-14)Added optionalendpoint_dispatch_prefixtable configuration to enable multiple
tables on the same endpoint.2.4.0 (2016-07-13)Made more parts ofBoundCellavailable for reuse.2.3.0 (2016-07-12)Added pass-through of extra arguments toLinkobjects for custom attributes.2.2.0 (2016-06-23)Fix missing namespace collection for column custimization of Table.from_model2.1.0 (2016-06-16)Renameddb_compat.register_field_factoryto the clearerregister_column_factoryImproved error reporting on missing django field type column factory declaration.Added iteration interface to table to loop over bound rowsAddedendpointmeta class parameter to table to enable custom json endpoints2.0.0 (2016-06-02)Support for ajax backendDependent tri.form and tri.query libraries have new major versions1.16.0 (2016-04-25)Minor bugfix for fields-from-model handling of auto fields1.15.0 (2016-04-21)Table.from_model implemented1.14.0 (2016-04-19)Addedafterattribute onColumnto enable custom column ordering (Seetri.declarative.sort_after())Enable mixing column definitions in both declared fields and class meta.Don’t show any results if the form is invalid1.13.0 (2016-04-08)Add python 3 support1.12.0 (2016-02-29)Changed syntax for specifying html attributes and classes. They are now use the same way of addressing as
other things, e.g.: Column(attrs__foo=”bar”, attrs__class__baz=True) will yield something like<th class=”baz” foo=bar>…</th>1.11.0 (2016-02-04)Fix missing evaluation of row__attr et al.1.10.0 (2016-01-28)Changed cell__template and row__template semantics slightly to enable customized cell ordering in templates.row__template implementations can now access a BoundCell object to use the default cell rendering.cell__template implementation are now assumed to render the <td> tags themself.1.9.0 (2016-01-19)Fixed to work with latest version of tri.form