{ "info": { "author": "Anders Hovm\u00f6ller", "author_email": "anders.hovmoller@trioptima.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6" ], "description": ".. image:: https://travis-ci.org/TriOptima/tri.table.svg?branch=master\n :target: https://travis-ci.org/TriOptima/tri.table\n\n\n.. image:: https://codecov.io/github/TriOptima/tri.table/coverage.svg?branch=master\n :target: https://codecov.io/github/TriOptima/tri.table?branch=master\n\n\ntri.table\n=========\n\ntri.table is a library to make full featured HTML tables easily:\n\n* generates header, rows and cells\n* grouping of headers\n* filtering\n* sorting\n* bulk edit\n* pagination\n* automatic rowspan\n* link creation\n* customization on multiple levels, all the way down to templates for cells\n\nAll these examples and a bigger example using many more features can be found in the examples django project.\n\nRead the full documentation for more.\n\n.. contents::\n\nSimple example\n--------------\n\n.. code:: python\n\n def readme_example_1(request):\n # Say I have a class...\n class Foo(object):\n def __init__(self, i):\n self.a = i\n self.b = 'foo %s' % (i % 3)\n self.c = (i, 1, 2, 3, 4)\n\n # and a list of them\n foos = [Foo(i) for i in xrange(4)]\n\n # I can declare a table:\n class FooTable(Table):\n a = Column.number() # This is a shortcut that results in the css class \"rj\" (for right justified) being added to the header and cell\n b = Column()\n c = Column(cell__format=lambda table, column, row, value, **_: value[-1]) # Display the last value of the tuple\n sum_c = Column(cell__value=lambda table, column, row, **_: sum(row.c), sortable=False) # Calculate a value not present in Foo\n\n # now to get an HTML table:\n return render_table_to_response(request, FooTable(data=foos), template='base.html')\n\nAnd this is what you get:\n\n.. image:: table_example_1.png\n\nFancy django features\n---------------------\n\nSay I have some models:\n\n.. code:: python\n\n class Foo(models.Model):\n a = models.IntegerField()\n\n def __unicode__(self):\n return 'Foo: %s' % self.a\n.. code:: python\n\n class Bar(models.Model):\n b = models.ForeignKey(Foo)\n c = models.CharField(max_length=255)\n\nNow I can display a list of Bars in a table like this:\n\n.. code:: python\n\n def readme_example_2(request):\n fill_dummy_data()\n\n class BarTable(Table):\n select = Column.select() # Shortcut for creating checkboxes to select rows\n b__a = Column.number( # Show \"a\" from \"b\". This works for plain old objects too.\n query__show=True, # put this field into the query language\n query__gui__show=True) # put this field into the simple filtering GUI\n c = Column(\n bulk=True, # Enable bulk editing for this field\n query_show=True,\n query__gui__show=True)\n\n return render_table_to_response(request, BarTable(data=Bar.objects.all()), template='base.html', paginate_by=20)\n\nThis gives me a view with filtering, sorting, bulk edit and pagination.\n\nAll these examples and a bigger example using many more features can be found in the examples django project.\n\nRead the full documentation for more.\n\nUsage\n-----\n\nAdd tri_form, tri_query, tri_table to INSTALLED_APPS.\n\nMotivation\n----------\n\ntri.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.\n\nThis 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 the `thead` and `tbody` had 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!\n\nWe 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.\n\nIt 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.\n\nWe 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.\n\nThis 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.\n\nRunning tests\n-------------\n\nYou need tox installed then just `make test`.\n\n\nLicense\n-------\n\nBSD\n\n\nDocumentation\n-------------\n\nhttps://tritable.readthedocs.org.\n\n\nChangelog\n---------\n\n8.1.0 (2019-10-??)\n~~~~~~~~~~~~~~~~~~\n\n* Implemented `Table.actions` as a replacement for `render_table`s argument `links`.\n\n* `Column.multi_choice_queryset` was broken.\n\n* Fixed `many_to_many` shortcut.\n\n* Deprecated the following parameters to `render_table`:\n * `template`: replaced by `Table.template`\n * `paginate_by`: replaced by `Table.page_size`\n * `show_hits`: no replacement\n * `hit_label`: no replacement\n * `page`: no replacement\n * `blank_on_empty`: no replacement\n * `links`: replaced by `Table.actions`\n\n* Bumped dependency tri.declarative to 4.x\n\n\n8.0.0 (2019-06-14)\n~~~~~~~~~~~~~~~~~~\n\n* Renamed module from `tri.table` to `tri_table`\n\n* Dropped support for python2 and Django < 2.0\n\n\n7.0.2 (2019-05-06)\n~~~~~~~~~~~~~~~~~~\n\n* Fixed cases where from_model lost the type when inheriting\n\n\n7.0.1 (2019-05-03)\n~~~~~~~~~~~~~~~~~~\n\n* Fixed a bug where columns that had query or bulk but attr=None would crash\n\n\n7.0.0 (2019-04-12)\n~~~~~~~~~~~~~~~~~~\n\n* Make `Column` shortcuts compatible with subclassing. The previous fix didn't work all the way.\n\n* Use the new major tri.declarative, and update to follow the new style of class member shortcuts\n\n* Removed support for django 1.8\n\n* `bulk_queryset` is now usable to create your own bulk actions without using `Table.bulk_form`\n\n* Bulk form now auto creates via `Form.from_model` correctly\n\n* Query is now auto created via `Query.from_model` correctly\n\n6.3.0 (2019-03-15)\n~~~~~~~~~~~~~~~~~~\n\n* Make Column shortcuts compatible with subclassing\n\n\n6.2.1 (2019-03-05)\n~~~~~~~~~~~~~~~~~~\n\n* Fixed a crash when you used a custom paginator in django 2.0+\n\n\n6.2.0 (2019-03-04)\n~~~~~~~~~~~~~~~~~~\n\n* Fixes for jinja2 compatibility (still not fully working)\n\n* `preprocess_data` now takes a new keyword argument `table`\n\n* You can now get the paginator context itself via `Table.paginator_context`\n\n* Paginator template is configurable\n\n* Fixed a bug where we triggered our own deprecation warning for `Column`\n\n* Use the new paginator API for django 2.0+\n\n\n6.1.0 (2019-01-29)\n~~~~~~~~~~~~~~~~~~\n\n* Deprecated `Column` argument `attrs` in favor of `header__attrs`\n\n* Added CSS classes `ascending`/`descending` on headers\n\n* Added ability to customize superheaders via `Column.superheader`\n\n* Added ability to customize `Column` header template via `header__template`\n\n* Deprecated `title` parameter to `Column`\n\n* Deprecated `css_class` parameter to `Column`\n\n* Removed class='row{1,2}' from